• 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
Re: NSAttributedString behaving badly
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSAttributedString behaving badly


  • Subject: Re: NSAttributedString behaving badly
  • From: Andy Lee <email@hidden>
  • Date: Mon, 3 Jul 2006 10:59:13 -0400

On Jul 3, 2006, at 10:15 AM, D.K. Johnston wrote:

I have an array of NSString text lines, each of which is terminated by \n. I want to append each line (textLine), along with some line citation information, to an NSAttributedString (theText), which will then be displayed in a read-only text view. The citation information is in an NSDictionary called "attributes". I'm doing it like this:

   // construct a range for the new line
   unsigned location = [theText length];
   NSRange range = NSMakeRange(location, 1);

   // add the new line to the text string
   id attrib = [[NSAttributedString alloc] initWithString:textLine];
   [theText appendAttributedString:attrib];
   [attrib release];

   // apply the attributes
   [theText setAttributes:attributes range:range];

The idea is that I can get the citation data for the selected line in the text view simply by reading the attributes of its first character.

But something is going wrong. When I process an NSString array containing about 8,000 lines, applying 2 attributes, it takes about 3 seconds to complete the loop. That's bad enough. But when I process an NSString array containing about 12,000 lines, applying 3 attributes, the loop is still running after 3 minutes.

Have you tried profiling to see where the time is being spent? A trivial "sample" would be to break in the debugger after 10 seconds and see what the heck it's doing. For more scientific data, you could use profiling tools like Shark or Sampler.


Is there an NSTextView being updated with the contents of theText? It sounds like not, but if so, the rendering time could be slowing you down.

Is there a lot of virtual memory swapping going on? Maybe a local autorelease pool would help.

Have you tried pinpointing the problem by trying 12,000 lines with 2 attributes, then maybe 11,000 lines, then 10,000, etc.? That is, try to find a breaking point where the processing time jumps above, say, 5 seconds. Maybe it's a particular number of lines. Maybe it's the contents of one specific line in your input. If it's hanging on one particular line, maybe you could pinpoint it by doing a small NSLog() on each iteration of your loop.

--Andy

_______________________________________________
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


References: 
 >NSAttributedString behaving badly (From: "D.K. Johnston" <email@hidden>)

  • Prev by Date: Re: flipping between tabs in tab view
  • Next by Date: Re: NSMutable Data Crash
  • Previous by thread: NSAttributedString behaving badly
  • Next by thread: Re: flipping between tabs in tab view
  • Index(es):
    • Date
    • Thread