ObjFW  Check-in [57a6e8ef79]

Overview
Comment:Improve code readability.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 57a6e8ef7955c9ff67881c52eec8b73998c8c79f0eaed5441987b45cb3a2c7b4
User & Date: js on 2013-03-30 20:07:08
Other Links: manifest | tags
Context
2013-03-31
10:04
Improve OFTLSSocket protocol. check-in: b7b67d7119 user: js tags: trunk
2013-03-30
20:07
Improve code readability. check-in: 57a6e8ef79 user: js tags: trunk
2013-03-23
19:29
objfw-compile: Allow -F. check-in: 902d016a57 user: js tags: trunk
Changes

Modified src/OFDataArray.m from [bf3d520a45] to [cc46586b15].

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
		const char *cString;
		size_t i;

		_itemSize = 1;
		_count = [string
		    cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII];

		if (_count & 1)
			@throw [OFInvalidFormatException
			    exceptionWithClass: [self class]];

		_count >>= 1;
		cString = [string
		    cStringWithEncoding: OF_STRING_ENCODING_ASCII];
		_items = [self allocMemoryWithSize: _count];

		for (i = 0; i < _count; i++) {
			uint8_t c1 = cString[2 * i];
			uint8_t c2 = cString[2 * i + 1];







|



|







216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
		const char *cString;
		size_t i;

		_itemSize = 1;
		_count = [string
		    cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII];

		if (_count % 2 != 0)
			@throw [OFInvalidFormatException
			    exceptionWithClass: [self class]];

		_count /= 2;
		cString = [string
		    cStringWithEncoding: OF_STRING_ENCODING_ASCII];
		_items = [self allocMemoryWithSize: _count];

		for (i = 0; i < _count; i++) {
			uint8_t c1 = cString[2 * i];
			uint8_t c2 = cString[2 * i + 1];

Modified src/OFDictionary_hashtable.m from [312b1063e8] to [522c9d1fef].

209
210
211
212
213
214
215






216
217
218
219
220
221
222
223
		if ((object = va_arg(arguments, id)) == nil)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: [self class]
				      selector: _cmd];

		count = 1;
		for (; va_arg(argumentsCopy, id) != nil; count++);






		count >>= 1;

		_mapTable = [[OFMapTable alloc]
		    initWithKeyFunctions: keyFunctions
			  valueFunctions: valueFunctions
				capacity: count];

		[_mapTable setValue: object







>
>
>
>
>
>
|







209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
		if ((object = va_arg(arguments, id)) == nil)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: [self class]
				      selector: _cmd];

		count = 1;
		for (; va_arg(argumentsCopy, id) != nil; count++);

		if (count % 2 != 0)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: [self class]
				      selector: _cmd];

		count /= 2;

		_mapTable = [[OFMapTable alloc]
		    initWithKeyFunctions: keyFunctions
			  valueFunctions: valueFunctions
				capacity: count];

		[_mapTable setValue: object

Modified src/OFHTTPClient.m from [39b7903990] to [821496c01f].

301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
- (OFTCPSocket*)OF_createSocketForRequest: (OFHTTPRequest*)request
{
	OFURL *URL = [request URL];
	OFTCPSocket *socket;

	[self close];

	if ([[URL scheme] isEqual: @"http"])
		socket = [OFTCPSocket socket];
	else {
		if (of_tls_socket_class == Nil)
			@throw [OFUnsupportedProtocolException
			    exceptionWithClass: [self class]
					   URL: URL];

		socket = [[[of_tls_socket_class alloc] init]
		    autorelease];
	}


	if ([_delegate respondsToSelector:
	    @selector(client:didCreateSocket:request:)])
		[_delegate client: self
		  didCreateSocket: socket
			  request: request];








|
<
<







|
>







301
302
303
304
305
306
307
308


309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
- (OFTCPSocket*)OF_createSocketForRequest: (OFHTTPRequest*)request
{
	OFURL *URL = [request URL];
	OFTCPSocket *socket;

	[self close];

	if ([[URL scheme] isEqual: @"https"]) {


		if (of_tls_socket_class == Nil)
			@throw [OFUnsupportedProtocolException
			    exceptionWithClass: [self class]
					   URL: URL];

		socket = [[[of_tls_socket_class alloc] init]
		    autorelease];
	} else
		socket = [OFTCPSocket socket];

	if ([_delegate respondsToSelector:
	    @selector(client:didCreateSocket:request:)])
		[_delegate client: self
		  didCreateSocket: socket
			  request: request];

Modified src/OFMapTable.m from [7caa69a7b0] to [9fc4f60d3b].

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

		if (capacity > UINT32_MAX ||
		    capacity > UINT32_MAX / sizeof(*_buckets) ||
		    capacity > UINT32_MAX / 8)
			@throw [OFOutOfRangeException
			    exceptionWithClass: [self class]];

		for (_capacity = 1; _capacity < capacity; _capacity <<= 1);
		if (capacity * 8 / _capacity >= 6)
			_capacity <<= 1;

		if (_capacity < MIN_CAPACITY)
			_capacity = MIN_CAPACITY;

		_buckets = [self allocMemoryWithSize: sizeof(*_buckets)
					       count: _capacity];








|

|







136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

		if (capacity > UINT32_MAX ||
		    capacity > UINT32_MAX / sizeof(*_buckets) ||
		    capacity > UINT32_MAX / 8)
			@throw [OFOutOfRangeException
			    exceptionWithClass: [self class]];

		for (_capacity = 1; _capacity < capacity; _capacity *= 2);
		if (capacity * 8 / _capacity >= 6)
			_capacity *= 2;

		if (_capacity < MIN_CAPACITY)
			_capacity = MIN_CAPACITY;

		_buckets = [self allocMemoryWithSize: sizeof(*_buckets)
					       count: _capacity];

297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
	if (count > UINT32_MAX || count > UINT32_MAX / sizeof(*_buckets) ||
	    count > UINT32_MAX / 8)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	fullness = count * 8 / _capacity;

	if (fullness >= 6)
		capacity = _capacity << 1;
	else if (fullness <= 1)
		capacity = _capacity >> 1;
	else
		return;

	/*
	 * Don't downsize if we have an initial capacity or if we would fall
	 * below the minimum capacity.
	 */







|

|







297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
	if (count > UINT32_MAX || count > UINT32_MAX / sizeof(*_buckets) ||
	    count > UINT32_MAX / 8)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	fullness = count * 8 / _capacity;

	if (fullness >= 6)
		capacity = _capacity * 2;
	else if (fullness <= 1)
		capacity = _capacity / 2;
	else
		return;

	/*
	 * Don't downsize if we have an initial capacity or if we would fall
	 * below the minimum capacity.
	 */

Modified src/OFString+XMLUnescaping.m from [467acead25] to [baacfe9bd9].

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
			return nil;

		entity++;
		length--;

		for (i = 0; i < length; i++) {
			if (entity[i] >= '0' && entity[i] <= '9')
				c = (c << 4) + (entity[i] - '0');
			else if (entity[i] >= 'A' && entity[i] <= 'F')
				c = (c << 4) + (entity[i] - 'A' + 10);
			else if (entity[i] >= 'a' && entity[i] <= 'f')
				c = (c << 4) + (entity[i] - 'a' + 10);
			else
				return nil;
		}
	} else {
		for (i = 0; i < length; i++) {
			if (entity[i] >= '0' && entity[i] <= '9')
				c = (c * 10) + (entity[i] - '0');







|

|

|







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
			return nil;

		entity++;
		length--;

		for (i = 0; i < length; i++) {
			if (entity[i] >= '0' && entity[i] <= '9')
				c = (c << 4) | (entity[i] - '0');
			else if (entity[i] >= 'A' && entity[i] <= 'F')
				c = (c << 4) | (entity[i] - 'A' + 10);
			else if (entity[i] >= 'a' && entity[i] <= 'f')
				c = (c << 4) | (entity[i] - 'a' + 10);
			else
				return nil;
		}
	} else {
		for (i = 0; i < length; i++) {
			if (entity[i] >= '0' && entity[i] <= '9')
				c = (c * 10) + (entity[i] - '0');

Modified src/runtime/hashtable.m from [2747b40d13] to [3f8cbae000].

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
	struct objc_hashtable_bucket *bucket;

	hash = objc_hash_string(key);
	assert(h->count + 1 <= UINT32_MAX / 4);

	if ((h->count + 1) * 4 / (h->last_idx + 1) >= 3) {
		struct objc_hashtable_bucket **ndata;
		uint32_t nsize = (h->last_idx + 1) << 1;

		assert(nsize > 0);

		ndata = malloc(nsize * sizeof(struct objc_hashtable_bucket*));
		if (ndata == NULL)
			OBJC_ERROR("Not enough memory to insert into hash "
			    "table!");







|







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
	struct objc_hashtable_bucket *bucket;

	hash = objc_hash_string(key);
	assert(h->count + 1 <= UINT32_MAX / 4);

	if ((h->count + 1) * 4 / (h->last_idx + 1) >= 3) {
		struct objc_hashtable_bucket **ndata;
		uint32_t nsize = (h->last_idx + 1) * 2;

		assert(nsize > 0);

		ndata = malloc(nsize * sizeof(struct objc_hashtable_bucket*));
		if (ndata == NULL)
			OBJC_ERROR("Not enough memory to insert into hash "
			    "table!");

Modified src/runtime/sparsearray.m from [89c18b15e1] to [be43ba8163].

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
}

void
objc_sparsearray_set(struct objc_sparsearray *s, uint32_t idx, const void *obj)
{
#ifdef OF_SELUID24
	uint8_t i = idx >> 16;
	uint8_t j = idx >>  8;
	uint8_t k = idx;
#else
	uint8_t i = idx >> 8;
	uint8_t j = idx;
#endif

	if (s->buckets[i] == empty_level2) {







|







125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
}

void
objc_sparsearray_set(struct objc_sparsearray *s, uint32_t idx, const void *obj)
{
#ifdef OF_SELUID24
	uint8_t i = idx >> 16;
	uint8_t j = idx >> 8;
	uint8_t k = idx;
#else
	uint8_t i = idx >> 8;
	uint8_t j = idx;
#endif

	if (s->buckets[i] == empty_level2) {