• 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 12:54:25 +0100

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

On Thu, 15 Aug 2002 17:54:35 -0700, Dave Camp <email@hidden> said:

My first attempt at populating the menu was [popup addItemsWithTities:
myArray]; However, this is terribly slow (several seconds). Stopping in
the debugger shows that NSPopUpButton iterates my array, and before
adding each item it checks to see if there is already an item in the
menu with the same title. Obviously, this is a poor choice for me (over
20,000 string compares).

Yes - I regard this behavior as a bug, by the way, since it isn't
documented and besides, when I say add an item I mean add an item,
regardless of whether another item with that title already exists.

It is (sort of) documented. The class doc for NSPopUpButton mentions that all add and remove methods call -synchronizeTitleAndSelectedItem. If duplicates weren't removed, wouldn't it sort of screw up methods like -indexOfItemWithTitle: -itemWithTitle: and -selectItemWithTitle: ? The way I work around putting duplicate titles into popups is to populate the menu with a for loop and (as you've done in your example) grab the string value of the counter and insert it in the title string, viz "1 Duplicate", "2 Duplicate", "3 Hey a new one" etc. Not the most aesthetically perfect solution, perhaps, but hey ho.

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?

-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.

  • Follow-Ups:
    • Re: NSPopUpButton addItemsWithTitles is way slow
      • From: Jeremy Dronfield <email@hidden>
References: 
 >Re: NSPopUpButton addItemsWithTitles is way slow (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: Saving ruler markers to defaults
  • Next by Date: Re: Need help
  • Previous by thread: Re: NSPopUpButton addItemsWithTitles is way slow
  • Next by thread: Re: NSPopUpButton addItemsWithTitles is way slow
  • Index(es):
    • Date
    • Thread