• 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
Repetitive Appending of Strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Repetitive Appending of Strings


  • Subject: Repetitive Appending of Strings
  • From: Andrew Merenbach <email@hidden>
  • Date: Tue, 12 Feb 2008 08:47:33 -0800

Hi, all,

I have been working on a program that displays an extended output for a division equation, which involves a loop that continually appends a string, based on a number, to a longer string that is displayed to the user at the end of the process. My algorithm for everything past the decimal point (out to a number of digits determined by the variable "scale") looks like this:

		for (n = 0; n < scale && !self.isCancelled; ++n) {
			b = 10 * (b - q * a);
			q = floor(b / a);
			[quotientString appendFormat:@"%i", q];
		}

Note that call to -appendFormat. This is a beautiful solution in terms of simplicity, but for long outputs it's calling a method repeatedly.

What are my options here? The most simple optimization would involve using an IMP and creating a function pointer to a method, yes?

Are there, however, other options available, ones that might be better? For example, would it be more efficient (I'd imagine that it would be) if I malloc'ed, or NSZoneMalloc'ed, a unichar pointer and then used -initWithCharacters:length: or - initWithCharactersNoCopy:length:freeWhenDone:?

But can people localize their numbers, thus rendering the unichar option insufficient due to its lack of ability to be localized easily? or am I missing an obvious solution for the unichar method, which -- if it's more efficient, and also sufficient -- I'd really like to use?

Cheers,
	Andrew
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Repetitive Appending of Strings
      • From: "Michael Ash" <email@hidden>
    • Re: Repetitive Appending of Strings
      • From: glenn andreas <email@hidden>
  • Prev by Date: Problems with keyboard shortcuts without modifiers
  • Next by Date: Re: Event Tap strangeness
  • Previous by thread: Re: Problems with keyboard shortcuts without modifiers
  • Next by thread: Re: Repetitive Appending of Strings
  • Index(es):
    • Date
    • Thread