FROM : Adam R. Maxwell
DATE : Mon May 12 00:39:33 2008
On May 11, 2008, at 2:45 PM, Jérome Laurens wrote:
> Le 11 mai 08 à 04:42, Ali Ozer a écrit :
>
>> To extract a word range from a string, it may be easier to use
>> something like NSScanner:
>>
>> // Defining the words
>> NSCharacterSet *validWordSet = [NSCharacterSet
>> alphanumericCharacterSet]; // Or however you want to define words
>> NSCharacterSet *wordBreakSet = [validWordSet invertedSet];
>>
>> // Set up a scanner
>> NSScanner *scanner = [NSScanner scannerWithString:yourString];
>> [scanner setCharactersToBeSkipped:nil]; // We will manage
>> skipping ourselves (since we need to find the beginning of the word)
>
> A long time ago, I played seriously with NSScanner to implement some
> syntax coloring.
> It was unbearably slow, and I ended with the conclusion that
> [NSScanner scannerWithString:]; was making a copy of the given string.
> So I reimplemented my own NSScanner and it was way faster.
>
> Is it true that NSScanner duplicates the string?
Interesting question...I wrote a quick test program and set a
breakpoint on -[NSCFString copyWithZone:], and NSScanner indeed copied
it. For immutable strings, that's probably a retain, but it could be
pretty expensive for mutable strings or the NSTextStorage proxy.
The main performance problem I've had with NSScanner is that -
[NSScanner scanCharactersFromSet:] creates an autoreleased inverted
NSCharacterSet, which can blow up an autorelease pool pretty quickly
(rdar://problem/4652388). My conclusion is that it's not great for
parsing large strings or in a loop.
--
Adam_______________________________________________
Cocoa-dev mailing list (<email_removed>)
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:
http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
This email sent to <email_removed>
DATE : Mon May 12 00:39:33 2008
On May 11, 2008, at 2:45 PM, Jérome Laurens wrote:
> Le 11 mai 08 à 04:42, Ali Ozer a écrit :
>
>> To extract a word range from a string, it may be easier to use
>> something like NSScanner:
>>
>> // Defining the words
>> NSCharacterSet *validWordSet = [NSCharacterSet
>> alphanumericCharacterSet]; // Or however you want to define words
>> NSCharacterSet *wordBreakSet = [validWordSet invertedSet];
>>
>> // Set up a scanner
>> NSScanner *scanner = [NSScanner scannerWithString:yourString];
>> [scanner setCharactersToBeSkipped:nil]; // We will manage
>> skipping ourselves (since we need to find the beginning of the word)
>
> A long time ago, I played seriously with NSScanner to implement some
> syntax coloring.
> It was unbearably slow, and I ended with the conclusion that
> [NSScanner scannerWithString:]; was making a copy of the given string.
> So I reimplemented my own NSScanner and it was way faster.
>
> Is it true that NSScanner duplicates the string?
Interesting question...I wrote a quick test program and set a
breakpoint on -[NSCFString copyWithZone:], and NSScanner indeed copied
it. For immutable strings, that's probably a retain, but it could be
pretty expensive for mutable strings or the NSTextStorage proxy.
The main performance problem I've had with NSScanner is that -
[NSScanner scanCharactersFromSet:] creates an autoreleased inverted
NSCharacterSet, which can blow up an autorelease pool pretty quickly
(rdar://problem/4652388). My conclusion is that it's not great for
parsing large strings or in a loop.
--
Adam_______________________________________________
Cocoa-dev mailing list (<email_removed>)
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:
http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| Lincoln Green | May 10, 22:26 | |
| Nathan Kinsinger | May 11, 02:46 | |
| Ali Ozer | May 11, 04:42 | |
| Ali Ozer | May 11, 04:45 | |
| Jérome Laurens | May 11, 23:45 | |
| Kyle Sluder | May 11, 23:50 | |
| Adam R. Maxwell | May 12, 00:39 |






Cocoa mail archive

