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


Ignore:
Timestamp:
Aug 12, 2002, 1:14:02 PM (23 years ago)
Author:
darin
Message:

top level:

  • Tests/WebFoundation-Misc/ifnsurlextensions-test.m: (TestURLCommon): Add tests for the new WebNSURLExtras methods.
  • Tests/libiftest/IFCheckLeaks.c: (IFCheckLeaksAtExit): Remove workaround for CFPreferences race condition; it's now in WebFoundation.

JavaScriptCore:

Speed improvements. 19% faster on cvs-js-performance, 1% on cvs-static-urls.

Use global string objects for length and other common property names rather
than constantly making and destroying them. Use integer versions of get() and
other related calls rather than always making a string.

Also get rid of many unneeded constructors, destructors, copy constructors, and
assignment operators. And make some functions non-virtual.

  • kjs/internal.h:
  • kjs/internal.cpp: (NumberImp::toUInt32): Implement. (ReferenceImp::ReferenceImp): Special case for numeric property names. (ReferenceImp::getPropertyName): Moved guts here from ValueImp. Handle numeric case. (ReferenceImp::getValue): Moved guts here from ValueImp. Handle numeric case. (ReferenceImp::putValue): Moved guts here from ValueImp. Handle numeric case. (ReferenceImp::deleteValue): Added. Handle numeric case.
  • kjs/array_object.h:
  • kjs/array_object.cpp: All-new array implementation that stores the elements in a C++ array rather than in a property map. (ArrayInstanceImp::ArrayInstanceImp): Allocate the C++ array. (ArrayInstanceImp::~ArrayInstanceImp): Delete the C++ array. (ArrayInstanceImp::get): Implement both the old version and the new overload that takes an unsigned index for speed. (ArrayInstanceImp::put): Implement both the old version and the new overload that takes an unsigned index for speed. (ArrayInstanceImp::hasProperty): Implement both the old version and the new overload that takes an unsigned index for speed. (ArrayInstanceImp::deleteProperty): Implement both the old version and the new overload that takes an unsigned index for speed. (ArrayInstanceImp::setLength): Added. Used by the above to resize the array. (ArrayInstanceImp::mark): Mark the elements of the array too. (ArrayPrototypeImp::ArrayPrototypeImp): Pass the length to the array instance constructor.
  • kjs/bool_object.cpp:
  • kjs/date_object.cpp:
  • kjs/error_object.cpp:
  • kjs/function.cpp:
  • kjs/function_object.cpp:
  • kjs/math_object.cpp:
  • kjs/nodes.cpp:
  • kjs/nodes.h:
  • kjs/number_object.cpp:
  • kjs/object_object.cpp:
  • kjs/regexp_object.cpp:
  • kjs/string_object.cpp:
  • kjs/nodes2string.cpp: (SourceStream::operator<<): Add a special case for char now that you can't create a UString from a char implicitly.
  • kjs/object.h:
  • kjs/object.cpp: (ObjectImp::get): Call through to the string version if the numeric version is not implemented. (ObjectImp::put): Call through to the string version if the numeric version is not implemented. (ObjectImp::hasProperty): Call through to the string version if the numeric version is not implemented. (ObjectImp::deleteProperty): Call through to the string version if the numeric version is not implemented.
  • kjs/types.h:
  • kjs/types.cpp: (Reference::Reference): Added constructors for the numeric property name case.
  • kjs/ustring.h: Made the constructor that turns a character into a string be explicit so we don't get numbers that turn themselves into strings.
  • kjs/ustring.cpp: (UString::UString): Detect the empty string case, and use a shared empty string. (UString::find): Add an overload for single character finds. (UString::rfind): Add an overload for single character finds. (KJS::operator==): Fix bug where it would call strlen(0) if the first string was not null. Also handle non-ASCII characters consistently with the rest of the code by casting to unsigned char just in case.
  • kjs/value.h: Make ValueImp and all subclasses non-copyable and non-assignable.
  • kjs/value.cpp: (ValueImp::toUInt32): New interface, mainly useful so we can detect array indices and not turn them into strings and back. (ValueImp::toInteger): Use the new toUInt32. Probably can use more improvement. (ValueImp::toInt32): Use the new toUInt32. Probably can use more improvement. (ValueImp::toUInt16): Use the new toUInt32. Probably can use more improvement. (ValueImp::getBase): Remove handling of the Reference case. That's in ReferenceImp now. (ValueImp::getPropertyName): Remove handling of the Reference case. That's in ReferenceImp now. (ValueImp::getValue): Remove handling of the Reference case. That's in ReferenceImp now. (ValueImp::putValue): Remove handling of the Reference case. That's in ReferenceImp now. (ValueImp::deleteValue): Added. Used so we can do delete the same way we do put.

WebFoundation:

  • CacheLoader.subproj/WebHTTPResourceLoader.m: (-[WebHTTPProtocolHandler createWFLoadRequest]): Fix handling of paths with queries and some other subtle path and port number handling issues by using _web_hostWithPort and _web_pathWithQuery.
  • Misc.subproj/WebNSURLExtras.h:
  • Misc.subproj/WebNSURLExtras.m: (-[NSURL _web_hostWithPort]): Added. (-[NSURL _web_pathWithQuery]): Added.
  • CacheLoader.subproj/WebResourceLoad.m: (initLoader): Get some random preference before creating threads. This makes it impossible to run into the CFPreferences race condition.

WebCore:

  • force-clean-timestamp: Need a full build because of KJS changes.
  • khtml/ecma/kjs_window.h: Need to store an Object, not an ObjectImp, because there's no way to copy an ObjectImp. KJS changes caught this mistake.
File:
1 edited

Legend:

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

    r1791 r1799  
    116116UChar UChar::null;
    117117UString::Rep UString::Rep::null = { 0, 0, 0, 1 };
     118UString::Rep UString::Rep::empty = { 0, 0, 0, 1 };
    118119UString UString::null;
    119120const int normalStatBufferSize = 4096;
     
    191192  }
    192193  int length = strlen(c);
     194  if (length == 0) {
     195    attach(&Rep::empty);
     196    return;
     197  }
    193198  UChar *d = new UChar[length];
    194199  for (int i = 0; i < length; i++)
     
    199204UString::UString(const UChar *c, int length)
    200205{
     206  if (length == 0) {
     207    attach(&Rep::empty);
     208    return;
     209  }
    201210  UChar *d = new UChar[length];
    202211  memcpy(d, c, length * sizeof(UChar));
     
    206215UString::UString(UChar *c, int length, bool copy)
    207216{
     217  if (length == 0) {
     218    attach(&Rep::empty);
     219    return;
     220  }
    208221  UChar *d;
    209222  if (copy) {
     
    224237  int aSize = a.size();
    225238  int bSize = b.size();
    226   UChar *d = new UChar[aSize + bSize];
     239  int length = aSize + bSize;
     240  if (length == 0) {
     241    attach(&Rep::empty);
     242    return;
     243  }
     244  UChar *d = new UChar[length];
    227245  memcpy(d, a.data(), aSize * sizeof(UChar));
    228246  memcpy(d + aSize, b.data(), bSize * sizeof(UChar));
    229   rep = Rep::create(d, aSize + bSize);
     247  rep = Rep::create(d, length);
    230248}
    231249
     
    467485int UString::find(const UString &f, int pos) const
    468486{
    469   if (isNull())
     487  if (size() < f.size())
    470488    return -1;
    471   long fsize = f.size() * sizeof(UChar);
    472489  if (pos < 0)
    473490    pos = 0;
    474491  const UChar *end = data() + size() - f.size();
     492  long fsize = f.size() * sizeof(UChar);
     493  const void *fdata = f.data();
    475494  for (const UChar *c = data() + pos; c <= end; c++)
    476     if (!memcmp((void*)c, (void*)f.data(), fsize))
     495    if (!memcmp(c, fdata, fsize))
    477496      return (c-data());
    478497
     
    480499}
    481500
     501int UString::find(UChar ch, int pos) const
     502{
     503  if (pos < 0)
     504    pos = 0;
     505  const UChar *end = data() + size();
     506  for (const UChar *c = data() + pos; c < end; c++)
     507    if (*c == ch)
     508      return (c-data());
     509
     510  return -1;
     511}
     512
    482513int UString::rfind(const UString &f, int pos) const
    483514{
    484   if (isNull())
     515  if (size() < f.size())
    485516    return -1;
    486517  if (pos + f.size() >= size())
    487518    pos = size() - f.size();
    488519  long fsize = f.size() * sizeof(UChar);
     520  const void *fdata = f.data();
    489521  for (const UChar *c = data() + pos; c >= data(); c--) {
    490     if (!memcmp((void*)c, (void*)f.data(), fsize))
     522    if (!memcmp(c, fdata, fsize))
    491523      return (c-data());
    492524  }
     
    495527}
    496528
     529int UString::rfind(UChar ch, int pos) const
     530{
     531  if (isEmpty())
     532    return -1;
     533  if (pos + 1 >= size())
     534    pos = size() - 1;
     535  for (const UChar *c = data() + pos; c >= data(); c--) {
     536    if (*c == ch)
     537      return (c-data());
     538  }
     539
     540  return -1;
     541}
     542
    497543UString UString::substr(int pos, int len) const
    498544{
    499   if (isNull())
    500     return UString();
    501545  if (pos < 0)
    502546    pos = 0;
     
    552596bool KJS::operator==(const UString& s1, const char *s2)
    553597{
    554   if (s2 == 0L && s1.isNull())
    555     return true;
    556 
    557   if (s1.size() != (int) strlen(s2))
     598  if (s2 == 0) {
     599    return s1.isEmpty();
     600  }
     601
     602  if (s1.size() != (int)strlen(s2))
    558603    return false;
    559604
    560605  const UChar *u = s1.data();
    561606  while (*s2) {
    562     if (u->uc != *s2 )
     607    if (u->uc != (unsigned char)*s2)
    563608      return false;
    564609    s2++;
     
    583628  }
    584629  if (l < lmin)
    585     return (c1->unicode() < c2->unicode());
     630    return (c1->uc < c2->uc);
    586631
    587632  return (l1 < l2);
Note: See TracChangeset for help on using the changeset viewer.