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


Ignore:
Timestamp:
Aug 20, 2002, 10:23:31 PM (23 years ago)
Author:
darin
Message:

Three small changes to things that showed up in the sample.

5% speed increase on cvs-js-performance test.

  • kjs/simple_number.h: Check if double is an integer with d == (double)(int)d instead of remainder(d, 1) == 0, saving a function call each time.
  • kjs/ustring.cpp: (UString::find): Compare the first character before calling memcmp for the rest. (UString::rfind): Ditto. (KJS::operator==): Don't do a strlen before starting to compare the characters.
File:
1 edited

Legend:

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

    r1852 r1887  
    488488int UString::find(const UString &f, int pos) const
    489489{
    490   if (size() < f.size())
     490  int sz = size();
     491  int fsz = f.size();
     492  if (sz < fsz)
    491493    return -1;
     494  if (fsz == 0)
     495    return 0;
    492496  if (pos < 0)
    493497    pos = 0;
    494   const UChar *end = data() + size() - f.size();
    495   long fsize = f.size() * sizeof(UChar);
    496   const void *fdata = f.data();
     498  const UChar *end = data() + sz - fsz;
     499  long fsizeminusone = (fsz - 1) * sizeof(UChar);
     500  const UChar *fdata = f.data();
    497501  for (const UChar *c = data() + pos; c <= end; c++)
    498     if (!memcmp(c, fdata, fsize))
     502    if (*c == *fdata && !memcmp(c + 1, fdata + 1, fsizeminusone))
    499503      return (c-data());
    500504
     
    516520int UString::rfind(const UString &f, int pos) const
    517521{
    518   if (size() < f.size())
     522  int sz = size();
     523  int fsz = f.size();
     524  if (sz < fsz)
    519525    return -1;
    520   if (pos + f.size() >= size())
    521     pos = size() - f.size();
    522   long fsize = f.size() * sizeof(UChar);
    523   const void *fdata = f.data();
     526  if (fsz == 0)
     527    return 0;
     528  if (pos < 0)
     529    pos = 0;
     530  long fsizeminusone = (fsz - 1) * sizeof(UChar);
     531  const UChar *fdata = f.data();
    524532  for (const UChar *c = data() + pos; c >= data(); c--) {
    525     if (!memcmp(c, fdata, fsize))
     533    if (*c == *fdata && !memcmp(c + 1, fdata + 1, fsizeminusone))
    526534      return (c-data());
    527535  }
     
    603611  }
    604612
    605   if (s1.size() != (int)strlen(s2))
    606     return false;
    607 
    608613  const UChar *u = s1.data();
    609   while (*s2) {
     614  const UChar *uend = u + s1.size();
     615  while (u != uend && *s2) {
    610616    if (u->uc != (unsigned char)*s2)
    611617      return false;
     
    614620  }
    615621
    616   return true;
     622  return u == uend && *s2 == 0;
    617623}
    618624
Note: See TracChangeset for help on using the changeset viewer.