• 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: NSPopUpButton addItemsWithTitles is way slow
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPopUpButton addItemsWithTitles is way slow


  • Subject: Re: NSPopUpButton addItemsWithTitles is way slow
  • From: Jeremy Dronfield <email@hidden>
  • Date: Sat, 17 Aug 2002 15:24:34 +0100

On Saturday, August 17, 2002, at 12:54 pm, Jeremy Dronfield wrote:

On Saturday, August 17, 2002, at 05:18 am, Matt Neuburg wrote:

Still, I don't agree about the speed. I just tried this:

int i;
[popup1 removeAllItems];
for (i=0; i<300; i++) {
[popup1 addItemWithTitle: [NSString stringWithFormat: @"%i", i]];
}

and it certainly didn't take "several seconds" to complete. Perhaps there's
something else at play here.

Here's an uninformed guess: your strings are, at most, three characters long. If you replaced them with "Guatemala", "United States", "People's Democratic Republic of West Jibrovia" or whatever, wouldn't the speed of the string compares be affected?

Just proved myself wrong. I went back to a piece of code I wrote a while ago, for putting fonts in a popup menu. It goes like this:

int fontsCount;
NSFontManager *fontManager = [NSFontManager sharedFontManager];
NSArray *fontsArray = [[NSArray alloc] initWithArray:[fontManager availableFontFamilies]];
NSArray *sortedFontsArray = [fontsArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
for (fontsCount = 0; fontsCount < [sortedFontsArray count]; fontsCount++) {
[fontMenuPopUp addItemWithTitle:[sortedFontsArray objectAtIndex:fontsCount]];
}

Here, the array of font families (141 items, which surprised me - I take back my righteous guff about Apple guidelines) goes through the mill twice: once when it's sorted into alphabetical order, and again when it's added to the menu. I timed the process: 0.24 seconds. There IS something else at play in Dave's program. (NB I also tried dumping the array en bloc into the menu, using -addItemsWithTitles: and that was even quicker: 0.066 seconds.)
-Jeremy

=======================================
email@hidden // email@hidden
The Alchemy Pages:
- fractious fiction at http://freespace.virgin.net/jeremy.dronfield
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: NSPopUpButton addItemsWithTitles is way slow (From: Jeremy Dronfield <email@hidden>)

  • Prev by Date: Redrawing strings in a scroll view
  • Next by Date: Re: Creating Menu Items from NSMutableArray (but now wildly offtopic)
  • Previous by thread: Re: NSPopUpButton addItemsWithTitles is way slow
  • Next by thread: about my previous question
  • Index(es):
    • Date
    • Thread