Re: Repetitive Appending of Strings
Re: Repetitive Appending of Strings
- Subject: Re: Repetitive Appending of Strings
- From: Jens Alfke <email@hidden>
- Date: Tue, 12 Feb 2008 11:21:07 -0800
On 12 Feb '08, at 10:44 AM, John Stiles wrote:
Honestly I suspect the method call itself won't be that expensive,
but parsing and executing a format string does take a lot of time.
I have run into exactly this as a real hot-spot in a particular app.
(It was generating a hex string from a block of data; basically the
same kind of thing.)
My solution was to build the output in an NSMutableData, adding one or
two ASCII characters at a time using -appendBytes:length:, and then
create an NSString from the data using the NSAsciiStringEncoding. This
is pretty efficient, especially if you initialize the data object with
sufficient capacity.
On the other hand, it would probably take more than 1000 digits for
one instance of this to consume any user-detectable amount of time.
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden