iphone - Convert int to CFString without CFStringCreateWithFormat -
iphone - Convert int to CFString without CFStringCreateWithFormat -
the next extremely slow need.
cfstringcreatewithformat(null, null, cfstr("%d"), i);
currently takes 20,000ns in tests execute on 3gs. perhaps sounds fast, can create , release 2 nsmutabledictionaries in time executes. c weak, there must equivalent itoa
can utilize on ios.
this faster can get:
cfstringref tecfstringcreatewithinteger(nsinteger integer) { size_t size = 21; // long plenty 64 bits integer char buffer[size]; char *characters = buffer + size; *(--characters) = 0; // null-terminated string int sign = integer < 0 ? -1 : 1; { *(--characters) = '0' + (integer % 10) * sign; integer /= 10; } while ( integer ); if ( sign == -1 ) *(--characters) = '-'; homecoming cfstringcreatewithcstring(null, characters, kcfstringencodingascii); }
iphone objective-c
Comments
Post a Comment