Re: Speeding up XCode?
Re: Speeding up XCode?
- Subject: Re: Speeding up XCode?
- From: Frode <email@hidden>
- Date: Fri, 21 Oct 2005 19:53:40 +0200
Hello!
2005-10-21 kl. 18.37 skrev Andreas Grosam:
On 21.10.2005, at 12:09, Robert Dell wrote:
Jeff Laing wrote:
are you trying to make my code run slower?
Frankly, I don't see where anyone producing code that looks like this:
(from http://optusnet.dl.sourceforge.net/sourceforge/yasse/yasse-2.2.0.m)
digit = [[mystringvalue substringFromIndex: 0] substringToIndex: 1];
if ([digit isEqualTo: @"1"])
{
result = result * 10;
result = result + 1;
}
else if ([digit isEqualTo: @"0"])
{
result = result * 10;
};
mystringvalue = [mystringvalue substringFromIndex: 1];
};
gets to blame the compiler for producing sub-optimal runtime. The amount of
Objective-C overhead thats deliberately introduced here, for now good
reason, is mindboggling.
do you know of any other way i can get a string of say "4n35a" to return the numeric result of 435 or a string "2.3906" to return the numeric value of 23906?
there's a reason for this routine. when the system can't handle wht you need, make it. i'm inputting a string such as " 43 25% learning" and need the numeric value 4325 from that and ignore the rest.
If your input can be described through a grammar, you may consider to use a parser. I wouldn't use lex, bison, yacc or ANTLR, but some more light-wight solutions. Or create your own parser, possibly a regex solution is sufficient.
Hey, wait a minute before starting your flex project.
Check out CFStringGetCStringPtr() (or CFStringGetCharacterFromInlineBuffer()) and start from end of the string and you'll likely skip a possible text conversion, too.
Look here what CFString can do!
#define iswdigit(ch) (ch >= (UniChar)'0' && ch <= (UniChar)'9');
#define isdigit(ch) (ch > '0' && ch < '9')
- (SInt32)numberFromString:(NSString *)myNSString {
static UInt64 exp10[] = {1, 10, ..., 1000000000000000000ULL};
UInt64 result = 0;
int exp = 0;
const char *s = CFStringGetCStringPtr((CFStringRef)myNSString));
if(s) {
const char *ps = s + [myNSString length] + 1;
while(ps-- > s)
if(isdigit(*s)) {
assert(exp < sizeof(exp10) / sizeof(UInt32));
result += (ch - '0') * exp10[exp++];
}
}
else {
CFStringInlineBuffer ib;
CFRange r = CFRangeMake(0, [myNSString length]);
int i = r.length;
CFStringInitInlineBuffer((CFStringRef)myNSString, &ib, r);
while (i-- > 0) {
UniChar ch = CFStringGetCharacterFromInlineBuffer(&ib, i);
if(iswdigit(ch)) {
assert(exp < sizeof(exp10) / sizeof(UInt32));
result += (ch - (UniChar)'0') * exp10[exp++];
}
}
}
assert(result > (UInt64)SINT_MAX); // overflow
return((SInt32)result);
}
This will also work for say "2.0089" which earlier sample would convert to "289" and not "20089".
Regards,
/Roger
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden