discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's the faster way to change attributes of string ?


From: Alexander Malmberg
Subject: Re: What's the faster way to change attributes of string ?
Date: Wed, 06 Aug 2003 19:58:13 +0200

Yen-Ju Chen wrote:
> Hi,
> 
>   I'm improving the syntax-highlight in CodeEditorView right now.
>   What's the faster way to change thousands of attributes in NSTextStorage
> once ?

Depends, as always. :)

Are these only attribute changes? What are the changes like? Are you
setting new attributes for long or small ranges of characters? What's
the density of the changes (ie. how many characters have their
attributes changed)? Are the changes spread evenly over the string, or
do they come in "bursts"? Do the new attributes actually differ from the
old attributes?

>   I have two choices:
>   1. Build a new NSAttributedString and use [NSTextStorage
> setAttributedString:].
>   2. Directly use -addAttribute:value:range: on NSTextStorage.
>   Is there any significant difference in speed between this two ways ?

Unless you're changing the attributes of every single character in the
string, #2 should be faster, but perhaps not by much. However, for #2,
it's very important that you call -beginEditing before the first change
and -endEditing after the last change. Otherwise, #2 will be very slow.

>   It is slow when changing attributes of string larger than 80k (on Intel
> PIII 700 machine).

Profiling data would be very helpful. I don't have any hard data on
where the bottlenecks are, and I've been unable to get anything but
bogus values when trying to profile apps.

- Alexander Malmberg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]