ObjFW  Check-in [e250800382]

Overview
Comment:Optimize +[stringWithString:] and -[appendString:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e250800382e482ec83403cab1915ba14e5a289bcd3bbf0d482dc813259534da2
User & Date: js on 2011-07-08 21:08:34
Other Links: manifest | tags
Context
2011-07-08
21:26
Adjust TableGenerator to (not so) recent style changes. check-in: 30cdebfa2a user: js tags: trunk
21:08
Optimize +[stringWithString:] and -[appendString:]. check-in: e250800382 user: js tags: trunk
20:13
Rename -[deleteLeadingAndTrailingWhitespaces]. check-in: 7c66260ead user: js tags: trunk
Changes

Modified src/OFMutableString.m from [736e731460] to [8b9a1eb927].

246
247
248
249
250
251
252

253



254
255
256
257
258
259
260

- (void)appendString: (OFString*)string
{
	if (string == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];


	[self appendCString: [string cString]];



}

- (void)appendFormat: (OFConstantString*)format, ...
{
	va_list arguments;

	va_start(arguments, format);







>
|
>
>
>







246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264

- (void)appendString: (OFString*)string
{
	if (string == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	[self appendCStringWithoutUTF8Checking: [string cString]
					length: [string cStringLength]];

	if (string->s->isUTF8)
		s->isUTF8 = YES;
}

- (void)appendFormat: (OFConstantString*)format, ...
{
	va_list arguments;

	va_start(arguments, format);

Modified src/OFString.m from [39b88703df] to [518f441548].

578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
}

- initWithString: (OFString*)string
{
	self = [super init];

	@try {
		const char *cString;

		s = [self allocMemoryWithSize: sizeof(*s)];
		memset(s, 0, sizeof(*s));

		cString = [string cString];
		s->cStringLength = [string cStringLength];

		switch (of_string_check_utf8(cString, s->cStringLength)) {
		case 1:
			s->isUTF8 = YES;
			break;
		case -1:;
			@throw [OFInvalidEncodingException newWithClass: isa];
		}

		if ((s->cString = strdup(cString)) == NULL)
			@throw [OFOutOfMemoryException
			     newWithClass: isa
			    requestedSize: s->cStringLength + 1];

		@try {
			[self addMemoryToPool: s->cString];
		} @catch (id e) {
			free(s->cString);
			@throw e;
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







<
<



<

<
<
<
|
<
<
<
|
<
<
<
<
|
|
<
<
<
<
<
<







578
579
580
581
582
583
584


585
586
587

588



589



590




591
592






593
594
595
596
597
598
599
}

- initWithString: (OFString*)string
{
	self = [super init];

	@try {


		s = [self allocMemoryWithSize: sizeof(*s)];
		memset(s, 0, sizeof(*s));


		s->cStringLength = [string cStringLength];



		s->isUTF8 = string->s->isUTF8;








		s->cString = [self allocMemoryWithSize: s->cStringLength + 1];
		memcpy(s->cString, [string cString], s->cStringLength + 1);






	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}