[Openmcl-devel] Re: Hemlock performance investigation

Andrew P. Lentvorski, Jr. bsder at mail.allcaps.org
Fri Aug 27 23:04:15 PDT 2004


On Aug 27, 2004, at 4:47 PM, Andrew P. Lentvorski, Jr. wrote:

> Would the buffer happen to be one monolithic Unicode NSString (or is  
> something expecting to be accessing an NSString)?  If so, O(n)  
> accesses occur for every call to character-at-index since this is  
> Unicode.  It has to walk the entire string from the beginning since  
> the size in bytes of a character is not fixed.  If you scan every  
> character in the file, then that is also O(n).

This certainly might be the culprit.  Quoting the NSString  
documentation:

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ 
ObjC_classic/Classes/NSString.html#//apple_ref/doc/uid/20000154/ 
getCharacters_range_

getCharacters:range:

- (void)getCharacters:(unichar *)buffer range:(NSRange)aRange
Copies characters from aRange in the receiver into buffer, which must  
be large enough to contain them. Does not add a zero character. Raises  
an NSRangeException if any part of aRange lies beyond the end of the  
receiver.

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.

You will probably need to implement some of abstract methods on the  
NSString to see if this is actually the problem, though.

> 1) The better option is probably to use an NSTextView.  People seem to  
> be doing very nice editors with them.  (cf. subethaedit and smultron).

I had meant to imply subclassing NSTextView.  However, both of my  
references suggest that NSTextView should be used by providing a  
delegate rather than subclassing.  Mea culpa.

-a




More information about the Openmcl-devel mailing list