ObjFW  Check-in [c3c2bcca46]

Overview
Comment:Better API for the writte buffer of streams.
Can now be disabled without flushing and then be flushed later.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c3c2bcca46b82ae273978eda402032b270c243b4800068143e3677b016516f6f
User & Date: js on 2010-09-20 11:26:00
Other Links: manifest | tags
Context
2010-09-23
16:40
Some older gcc versions require an explicit cast here. check-in: 64a39262ca user: js tags: trunk
2010-09-20
11:26
Better API for the writte buffer of streams.
Can now be disabled without flushing and then be flushed later.
check-in: c3c2bcca46 user: js tags: trunk
11:14
Small optimization for ASCII strings in -[stringByXMLUnescaping]. check-in: 523bf78c46 user: js tags: trunk
Changes

Modified src/OFSeekableStream.m from [13775b9538] to [6733c391eb].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (void)seekToOffset: (off_t)offset
{
	[self flushWriteBuffer];
	[self _seekToOffset: offset];

	[self freeMemory: cache];
	cache = NULL;
	cacheLen = 0;
}

- (off_t)seekForwardWithOffset: (off_t)offset
{
	off_t ret;

	[self flushWriteBuffer];
	ret = [self _seekForwardWithOffset: offset - cacheLen];

	[self freeMemory: cache];
	cache = NULL;
	cacheLen = 0;

	return ret;
}

- (off_t)seekToOffsetRelativeToEnd: (off_t)offset
{
	off_t ret;

	[self flushWriteBuffer];
	ret = [self _seekToOffsetRelativeToEnd: offset];

	[self freeMemory: cache];
	cache = NULL;
	cacheLen = 0;

	return ret;
}
@end







<











<













<









29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (void)seekToOffset: (off_t)offset
{

	[self _seekToOffset: offset];

	[self freeMemory: cache];
	cache = NULL;
	cacheLen = 0;
}

- (off_t)seekForwardWithOffset: (off_t)offset
{
	off_t ret;


	ret = [self _seekForwardWithOffset: offset - cacheLen];

	[self freeMemory: cache];
	cache = NULL;
	cacheLen = 0;

	return ret;
}

- (off_t)seekToOffsetRelativeToEnd: (off_t)offset
{
	off_t ret;


	ret = [self _seekToOffsetRelativeToEnd: offset];

	[self freeMemory: cache];
	cache = NULL;
	cacheLen = 0;

	return ret;
}
@end

Modified src/OFStream.h from [dd21d0d02a] to [0915ec3638].

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@interface OFStream: OFObject
{
@public
	char   *cache;
@protected
	char   *wBuffer;
	size_t cacheLen, wBufferLen;
	BOOL   useWBuffer;
}

/**
 * Returns a boolean whether the end of the stream has been reached.
 *
 * \return A boolean whether the end of the stream has been reached
 */







|







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@interface OFStream: OFObject
{
@public
	char   *cache;
@protected
	char   *wBuffer;
	size_t cacheLen, wBufferLen;
	BOOL   bufferWrites;;
}

/**
 * Returns a boolean whether the end of the stream has been reached.
 *
 * \return A boolean whether the end of the stream has been reached
 */
194
195
196
197
198
199
200
201
202
203
204
205





206


207
208
209
210
211
212
213
 * \return The line that was read, autoreleased, or nil if the end of the
 *	   stream has been reached.
 */
- (OFString*)readTillDelimiter: (OFString*)delimiter
		  withEncoding: (enum of_string_encoding)encoding;

/**
 * Buffer all writes until flushWriteBuffer is called.
 */
- (void)bufferWrites;

/**





 * Writes everything in the write cache to the stream.


 */
- (void)flushWriteBuffer;

/**
 * Writes from a buffer into the stream.
 *
 * \param buf The buffer from which the data is written to the stream







|

|


>
>
>
>
>
|
>
>







194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
 * \return The line that was read, autoreleased, or nil if the end of the
 *	   stream has been reached.
 */
- (OFString*)readTillDelimiter: (OFString*)delimiter
		  withEncoding: (enum of_string_encoding)encoding;

/**
 * \return A boolean whether writes are buffered
 */
- (BOOL)bufferWrites;

/**
 * Enables or disables the write buffer.
 *
 * \param enable Whether the write buffer should be enabled or disabled
 */
- (void)setBufferWrites: (BOOL)enable;

/**
 * Writes everythig in the write buffer to the stream.
 */
- (void)flushWriteBuffer;

/**
 * Writes from a buffer into the stream.
 *
 * \param buf The buffer from which the data is written to the stream

Modified src/OFStream.m from [0bce414eb0] to [55e134209d].

511
512
513
514
515
516
517
518
519


520



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
		[self freeMemory: tmp];
	}

	/* Get rid of a warning, never reached anyway */
	assert(0);
}

- (void)bufferWrites
{


	useWBuffer = YES;



}

- (void)flushWriteBuffer
{
	if (wBuffer == NULL)
		return;

	[self _writeNBytes: wBufferLen
		fromBuffer: wBuffer];

	[self freeMemory: wBuffer];
	wBuffer = NULL;
	wBufferLen = 0;
	useWBuffer = NO;
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const char*)buf
{
	if (!useWBuffer)
		return [self _writeNBytes: size
			       fromBuffer: buf];
	else {
		wBuffer = [self resizeMemory: wBuffer
				      toSize: wBufferLen + size];
		memcpy(wBuffer + wBufferLen, buf, size);
		wBufferLen += size;







|

>
>
|
>
>
>













<





|







511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538

539
540
541
542
543
544
545
546
547
548
549
550
551
		[self freeMemory: tmp];
	}

	/* Get rid of a warning, never reached anyway */
	assert(0);
}

- (BOOL)bufferWrites
{
	return bufferWrites;
}

- (void)setBufferWrites: (BOOL)enable
{
	bufferWrites = enable;
}

- (void)flushWriteBuffer
{
	if (wBuffer == NULL)
		return;

	[self _writeNBytes: wBufferLen
		fromBuffer: wBuffer];

	[self freeMemory: wBuffer];
	wBuffer = NULL;
	wBufferLen = 0;

}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const char*)buf
{
	if (!bufferWrites)
		return [self _writeNBytes: size
			       fromBuffer: buf];
	else {
		wBuffer = [self resizeMemory: wBuffer
				      toSize: wBufferLen + size];
		memcpy(wBuffer + wBufferLen, buf, size);
		wBufferLen += size;