Re: NSString accessing characters
Re: NSString accessing characters
- Subject: Re: NSString accessing characters
- From: Ken Thomases <email@hidden>
- Date: Fri, 17 Jun 2011 03:40:12 -0500
On Jun 17, 2011, at 2:46 AM, Andreas Grosam wrote:
> I've written a parser which can natively parse any Unicode encoding form (UTF-8, UTF16 BE/LE, UTF-32 BE/LE). It takes iterators as input parameters, that is (const) pointers to uint8_t, uint16t and uint32_t which are selected according the Unicode encoding form of the given input text.
>
> So, the interface looks basically as followed (global free function):
>
> id parse(Iterator first, Iterator last);
>
> where 'Iterator' is one of the mentioned iterator types above, and 'first' is the beginning of the text, and 'last' is an iterator representing the end of the text.
>
>
> Given an NSString as input source, what is the fastest method to "feed" the parser?
>
> Also worth mentioning is the possible fact about hidden autoreleased memory objects, for instance when retrieving c-strings from the NSString object or when converting the NSString's internal encoding to some specified external form.
First, you're probably prematurely optimizing. The chance that accessing the string contents will be a significant portion of the time taken by parsing is small.
That said, I guess you should try CFStringGetCharactersPtr() and CFStringGetCStringPtr() first. If either returns non-NULL, then that's about as fast as you're going to get. After that, maybe use CFStringInitInlineBuffer() and CFStringGetCharacterFromInlineBuffer(), although that doesn't fit with your iterator interface. You could wrap an iterator around them easily, though. After that, it probably doesn't matter much. You'll be doing some combination of allocation and encoding conversion no matter what. So, go with the most convenient method, which will probably be back in Objective-C.
Regards,
Ken
_______________________________________________
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