• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fastest way to build an attributed string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fastest way to build an attributed string


  • Subject: Fastest way to build an attributed string
  • From: Fabian Lidman <email@hidden>
  • Date: Fri, 14 Jan 2005 12:26:06 +0100

Hello,
Q: What is the fastest way to create an attributed string from a sequence of string/dictionary pairs?


The application i'm working on needs to build an attributed string (specifically, an NSTextStorage) from data in an XML file. Depending on the size of the XML file, various number of dictionary/string pairs are concatenated into an attributed string:

while(thereIsMoreData) {
attributeRun = [xmlFile nextAttributeRun];
string = [xmlFile nextString];

[[textStorage mutableString] appendString: string];
[textStorage setAttributes: attributeRun range: NSMakeRange([textStorage length] - [string length], [string length])];
}


For a short XML file, this takes close to no time. For a longer file, the execution time seems to grow almost exponentially. A closer look in Shark reveals that the -setAttributes:range: call stands for about 80% of time. Peeking inside -setAttributes:range shows that it is doing a lot of dictionary comparison, possibly in an attempt to save memory by ensuring there are no duplicate attribute dictionaries. Memory, however, is less important than speed in this particular case. For a really large XML file it may take several minutes to create the attributed string.
Is there a faster way to create an attributed string?


_______________________________________________
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


  • Follow-Ups:
    • Re: Fastest way to build an attributed string
      • From: glenn andreas <email@hidden>
  • Prev by Date: Re: Zip-files
  • Next by Date: Re: Zip-files
  • Previous by thread: Semi-OT: WebCore > decodeData:, no longer working?
  • Next by thread: Re: Fastest way to build an attributed string
  • Index(es):
    • Date
    • Thread