Changeset 2754 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp


Ignore:
Timestamp:
Nov 19, 2002, 12:10:03 AM (23 years ago)
Author:
darin
Message:
  • a fix that gives another 1.5% on the iBench JavaScript test
  • kjs/ustring.cpp: (UString::from): Stop using sprintf to format integers.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/ustring.cpp

    r2749 r2754  
    245245UString UString::from(int i)
    246246{
    247   char buf[40];
    248   sprintf(buf, "%d", i);
    249 
    250   return UString(buf);
     247  return from((long)i);
    251248}
    252249
    253250UString UString::from(unsigned int u)
    254251{
    255   char buf[40];
    256   sprintf(buf, "%u", u);
    257 
    258   return UString(buf);
     252  UChar buf[20];
     253  UChar *p = buf + sizeof(buf);
     254 
     255  if (u == 0) {
     256    *--p = '0';
     257  } else {
     258    while (u) {
     259      *--p = (unsigned short)((u % 10) + '0');
     260      u /= 10;
     261    }
     262  }
     263 
     264  return UString(p, buf + sizeof(buf) - p);
    259265}
    260266
    261267UString UString::from(long l)
    262268{
    263   char buf[40];
    264   sprintf(buf, "%ld", l);
    265 
    266   return UString(buf);
     269  UChar buf[20];
     270  UChar *p = buf + sizeof(buf);
     271 
     272  if (l == 0) {
     273    *--p = '0';
     274  } else if (l == LONG_MIN) {
     275    char minBuf[20];
     276    sprintf(minBuf, "%ld", LONG_MIN);
     277    return UString(minBuf);
     278  } else {
     279    bool negative = false;
     280    if (l < 0) {
     281      negative = true;
     282      l = -l;
     283    }
     284    while (l) {
     285      *--p = (unsigned short)((l % 10) + '0');
     286      l /= 10;
     287    }
     288    if (negative) {
     289      *--p = '-';
     290    }
     291  }
     292 
     293  return UString(p, buf + sizeof(buf) - p);
    267294}
    268295
Note: See TracChangeset for help on using the changeset viewer.