Re: Efficiently getting characters
Re: Efficiently getting characters
- Subject: Re: Efficiently getting characters
- From: Bill Bumgarner <email@hidden>
- Date: Wed, 3 May 2006 08:44:09 -0700
On May 3, 2006, at 12:07 AM, Nir Soffer wrote:
On 03/05/2006, at 02:01, Douglas Davidson wrote:
to get characters from a long string. Unfortunately, there is a
note in the documentation that says
The abstract implementation of this method uses
characterAtIndex: repeatedly,
correctly extracting the characters, though very
inefficiently. Subclasses should
override it to provide a fast implementation.
but there is no indication how to do it efficiently (or why
NSString didn't bother to do it efficiently in the first place)
This note is intended for those who are writing subclasses of
NSString. If you are not writing a subclass of NSString, you
should ignore it. If you are not writing a subclass of NSString,
you are not using the abstract implementation of
getCharacters:range:. Instead, you are using an efficient
implementation supplied by one of the standard concrete subclasses.
The documentation must be fixed to make this clear.
The documentation is perfectly clear.
"Abstract implementation" implies just that -- the implementation
provided is an abstract that behaves correctly but is not intended to
be a specific, concrete, implementation of the defined algorithm.
The documentation then goes on to say that subclasses should override
said implementation to provide an optimal implementation for the
purposes of the subclass.
When using an instance of a class -- a method of a class -- and, in
particular, when subclassing a class, it is critical that one reads
the class documentation itself.
Along with a discussion of concrete private subclasses, class
clusters, and other implementation details, the NSString
documentation further states:
Any subclass of NSString must override the primitive instance methods
length and characterAtIndex:. These methods must operate on the
backing store that you provide for the characters of the string. For
this backing store you can use a static array, a dynamically
allocated buffer, a standard NSString object, or some other data type
or mechanism. You may also choose to override, partially or fully,
any other NSString method for which you want to provide an
alternative implementation. For example, for better performance it is
recommended that you override getCharacters:range: and give it a
faster implementation.
b.bum
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden