ObjFW  Check-in [d4b379485a]

Overview
Comment:Don't retain + autorelease objects returned from collections.

This increases performance and should not need to be handled by the
programmer in most cases.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d4b379485a840f2a0f5295a94b0a0f8fa8e01502e59d307afb3112566ba77807
User & Date: js on 2010-07-08 08:57:00
Other Links: manifest | tags
Context
2010-07-08
09:20
Optimize OFAutoreleasePool. check-in: f92e1c77a0 user: js tags: trunk
08:57
Don't retain + autorelease objects returned from collections. check-in: d4b379485a user: js tags: trunk
2010-07-07
21:08
Support for GNU libobjc won't be removed in the near future.
However, ObjFW-RT will be recommended once it's more mature.
check-in: 2924518400 user: js tags: trunk
Changes

Modified src/OFArray.m from [181efadcb0] to [3b7a88e4d4].

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
		[objs[i] retain];

	return new;
}

- (id)objectAtIndex: (size_t)index
{
	return [[*((OFObject**)[array itemAtIndex: index]) retain] autorelease];
}

- (size_t)indexOfObject: (OFObject*)obj
{
	id *objs = [array cArray];
	size_t i, count = [array count];








|







207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
		[objs[i] retain];

	return new;
}

- (id)objectAtIndex: (size_t)index
{
	return *((OFObject**)[array itemAtIndex: index]);
}

- (size_t)indexOfObject: (OFObject*)obj
{
	id *objs = [array cArray];
	size_t i, count = [array count];

244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
	return SIZE_MAX;
}

- (id)firstObject
{
	id *first = [array firstItem];

	return (first != NULL ? [[*first retain] autorelease] : nil);
}

- (id)lastObject
{
	id *last = [array lastItem];

	return (last != NULL ? [[*last retain] autorelease] : nil);
}

- (OFString*)componentsJoinedByString: (OFString*)separator
{
	OFString *str;
	OFString **objs = [array cArray];
	size_t i, count = [array count];







|






|







244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
	return SIZE_MAX;
}

- (id)firstObject
{
	id *first = [array firstItem];

	return (first != NULL ? *first : nil);
}

- (id)lastObject
{
	id *last = [array lastItem];

	return (last != NULL ? *last : nil);
}

- (OFString*)componentsJoinedByString: (OFString*)separator
{
	OFString *str;
	OFString **objs = [array cArray];
	size_t i, count = [array count];

Modified src/OFDictionary.m from [d6200e89ce] to [3d989f9035].

543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
	last = size;

	for (i = hash & (size - 1); i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key])
			return [[data[i]->object retain] autorelease];
	}

	if (i < last)
		return nil;

	/* In case the last bucket is already used */
	last = hash & (size - 1);

	for (i = 0; i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key])
			return [[data[i]->object retain] autorelease];
	}

	return nil;
}

- (size_t)count
{







|













|







543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
	last = size;

	for (i = hash & (size - 1); i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key])
			return data[i]->object;
	}

	if (i < last)
		return nil;

	/* In case the last bucket is already used */
	last = hash & (size - 1);

	for (i = 0; i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key])
			return data[i]->object;
	}

	return nil;
}

- (size_t)count
{

Modified src/OFXMLParser.m from [f763218ad7] to [bc650a7105].

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222


223
224
225
226
227
228
229
					name = [cache copy];
					prefix = nil;
				}

				if (buf[i] == '>' || buf[i] == '/') {
					OFString *ns;

					pool = [[OFAutoreleasePool alloc] init];
					ns = namespace_for_prefix(prefix,
					    namespaces);

					if (prefix != nil && ns == nil)
						@throw
						    [OFUnboundNamespaceException
						    newWithClass: isa
							  prefix: prefix];



					[delegate parser: self
					 didStartElement: name
					      withPrefix: prefix
					       namespace: ns
					      attributes: nil];








<








>
>







207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
					name = [cache copy];
					prefix = nil;
				}

				if (buf[i] == '>' || buf[i] == '/') {
					OFString *ns;


					ns = namespace_for_prefix(prefix,
					    namespaces);

					if (prefix != nil && ns == nil)
						@throw
						    [OFUnboundNamespaceException
						    newWithClass: isa
							  prefix: prefix];

					pool = [[OFAutoreleasePool alloc] init];

					[delegate parser: self
					 didStartElement: name
					      withPrefix: prefix
					       namespace: ns
					      attributes: nil];

293
294
295
296
297
298
299
300
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
326
327
328
329
330
331
332
333
334
335
336
337
338


339
340
341
342
343
344
345
				if (![[previous lastObject] isEqual: cache])
					@throw [OFMalformedXMLException
					    newWithClass: isa];
				[previous removeNObjects: 1];

				[cache setToCString: ""];

				pool = [[OFAutoreleasePool alloc] init];

				ns = namespace_for_prefix(prefix, namespaces);
				if (prefix != nil && ns == nil)
					@throw [OFUnboundNamespaceException
					    newWithClass: isa
						  prefix: prefix];
				[namespaces removeNObjects: 1];


				[delegate parser: self
				   didEndElement: name
				      withPrefix: prefix
				       namespace: ns];

				[pool release];


				[name release];
				[prefix release];
				name = prefix = nil;

				last = i + 1;
				state = (buf[i] == '>'
				    ? OF_XMLPARSER_OUTSIDE_TAG
				    : OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE);
			}
			break;

		/* Inside a tag, name found */
		case OF_XMLPARSER_IN_TAG:
			if (buf[i] == '>' || buf[i] == '/') {
				OFString *ns;

				pool = [[OFAutoreleasePool alloc] init];
				ns = namespace_for_prefix(prefix, namespaces);

				if (prefix != nil && ns == nil)
					@throw [OFUnboundNamespaceException
					    newWithClass: isa
						  prefix: prefix];



				[delegate parser: self
				 didStartElement: name
				      withPrefix: prefix
				       namespace: ns
				      attributes: attrs];








<
<





|
>








>
















<






>
>







294
295
296
297
298
299
300


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
326
327
328
329
330
331
332

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
				if (![[previous lastObject] isEqual: cache])
					@throw [OFMalformedXMLException
					    newWithClass: isa];
				[previous removeNObjects: 1];

				[cache setToCString: ""];



				ns = namespace_for_prefix(prefix, namespaces);
				if (prefix != nil && ns == nil)
					@throw [OFUnboundNamespaceException
					    newWithClass: isa
						  prefix: prefix];

				pool = [[OFAutoreleasePool alloc] init];

				[delegate parser: self
				   didEndElement: name
				      withPrefix: prefix
				       namespace: ns];

				[pool release];

				[namespaces removeNObjects: 1];
				[name release];
				[prefix release];
				name = prefix = nil;

				last = i + 1;
				state = (buf[i] == '>'
				    ? OF_XMLPARSER_OUTSIDE_TAG
				    : OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE);
			}
			break;

		/* Inside a tag, name found */
		case OF_XMLPARSER_IN_TAG:
			if (buf[i] == '>' || buf[i] == '/') {
				OFString *ns;


				ns = namespace_for_prefix(prefix, namespaces);

				if (prefix != nil && ns == nil)
					@throw [OFUnboundNamespaceException
					    newWithClass: isa
						  prefix: prefix];

				pool = [[OFAutoreleasePool alloc] init];

				[delegate parser: self
				 didStartElement: name
				      withPrefix: prefix
				       namespace: ns
				      attributes: attrs];