ObjFW  Check-in [c5c17fdd30]

Overview
Comment:Rename -[cacheWrites] to -[bufferWrites].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c5c17fdd30fecc21910629d0ba77e626a72c743620f20ba0a78fda4123ddbd24
User & Date: js on 2010-04-09 20:11:22
Other Links: manifest | tags
Context
2010-04-10
13:32
Prevent repeated evaluation of i in OF_BSWAP{16,32,64}_CONST. check-in: c5b72902da user: js tags: trunk
2010-04-09
20:11
Rename -[cacheWrites] to -[bufferWrites]. check-in: c5c17fdd30 user: js tags: trunk
17:06
Flush the write cache before seeking. check-in: c509ecf6c7 user: js tags: trunk
Changes

Modified src/OFSeekableStream.m from [943a2b61b5] to [8a407eb24d].

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
72
73
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
72
73







-
+













-
+













-
+









{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

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

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

	return self;
}

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

	[self flushWriteCache];
	[self flushWriteBuffer];
	ret = [self _seekForwardWithOffset: offset - cache_len];

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

	return ret;
}

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

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

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

	return ret;
}
@end

Modified src/OFStream.h from [8e74551eac] to [33ab04595d].

21
22
23
24
25
26
27
28
29
30



31
32
33
34
35
36
37
21
22
23
24
25
26
27



28
29
30
31
32
33
34
35
36
37







-
-
-
+
+
+







 * _writeNBytes:fromBuffer: and _atEndOfStream, but nothing else. Those are not
 * defined in the headers, but do the actual work. OFStream uses those and does
 * all the caching and other stuff. If you override these methods without the
 * _ prefix, you *WILL* break caching and get broken results!
 */
@interface OFStream: OFObject
{
	char   *cache, *wcache;
	size_t cache_len, wcache_len;
	BOOL   use_wcache;
	char   *cache, *wbuffer;
	size_t cache_len, wbuffer_len;
	BOOL   use_wbuffer;
}

/**
 * Returns a boolean whether the end of the stream has been reached.
 *
 * \return A boolean whether the end of the stream has been reached
 */
162
163
164
165
166
167
168
169

170
171

172
173
174
175
176

177
178
179
180
181
182
183
162
163
164
165
166
167
168

169
170

171
172
173
174
175

176
177
178
179
180
181
182
183







-
+

-
+




-
+







 * \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;

/**
 * Caches all writes until flushWriteCache is called.
 * Buffer all writes until flushWriteBuffer is called.
 */
- cacheWrites;
- bufferWrites;

/**
 * Writes everything in the write cache to the stream.
 */
- flushWriteCache;
- flushWriteBuffer;

/**
 * Writes from a buffer into the stream.
 *
 * \param buf The buffer from which the data is written to the stream
 * \param size The size of the data that should be written
 * \return The number of bytes written

Modified src/OFStream.m from [7fc39d31ba] to [86bdcc3dab].

33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47







-
+







	self = [super init];

	if (isa == [OFStream class])
		@throw [OFNotImplementedException newWithClass: isa
						      selector: _cmd];

	cache = NULL;
	wcache = NULL;
	wbuffer = NULL;

	return self;
}

- (BOOL)_atEndOfStream
{
	@throw [OFNotImplementedException newWithClass: isa
493
494
495
496
497
498
499
500

501
502

503
504
505
506
507

508
509

510
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
493
494
495
496
497
498
499

500
501

502
503
504
505
506

507
508

509
510
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







-
+

-
+




-
+

-
+


-
-
+
+

-
-
-
-
+
+
+
+







-
+



-
-
-
-
+
+
+
+







		[self freeMemory: tmp];
	}

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

- cacheWrites
- bufferWrites
{
	use_wcache = YES;
	use_wbuffer = YES;

	return self;
}

- flushWriteCache
- flushWriteBuffer
{
	if (wcache == NULL)
	if (wbuffer == NULL)
		return self;

	[self _writeNBytes: wcache_len
		fromBuffer: wcache];
	[self _writeNBytes: wbuffer_len
		fromBuffer: wbuffer];

	[self freeMemory: wcache];
	wcache = NULL;
	wcache_len = 0;
	use_wcache = NO;
	[self freeMemory: wbuffer];
	wbuffer = NULL;
	wbuffer_len = 0;
	use_wbuffer = NO;

	return self;
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const char*)buf
{
	if (!use_wcache)
	if (!use_wbuffer)
		return [self _writeNBytes: size
			       fromBuffer: buf];
	else {
		wcache = [self resizeMemory: wcache
				     toSize: wcache_len + size];
		memcpy(wcache + wcache_len, buf, size);
		wcache_len += size;
		wbuffer = [self resizeMemory: wbuffer
				      toSize: wbuffer_len + size];
		memcpy(wbuffer + wbuffer_len, buf, size);
		wbuffer_len += size;

		return size;
	}
}

- (void)writeInt8: (uint8_t)int8
{