Ignore:
Timestamp:
Jan 18, 2008, 1:05:16 PM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

Reviewed by Geoff.

  • Correctly report cost of appended strings to trigger GC.
  • kjs/ustring.cpp: (KJS::): (KJS::UString::Rep::create): (KJS::UString::UString): Don't create unnecssary objects. (KJS::UString::cost): Report cost if necessary but also keep track of reported cost.
  • kjs/ustring.h:

LayoutTests:

Reviewed by Geoff.

  • Correctly report cost of appended strings to trigger GC.
  • fast/js/garbage-collect-after-string-appends-expected.txt: Added.
  • fast/js/garbage-collect-after-string-appends.html: Added.
  • fast/js/resources/garbage-collect-after-string-appends.js: Added.
File:
1 edited

Legend:

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

    r27859 r29639  
    7878}
    7979
    80 // we'd rather not do shared substring append for small strings, since
    81 // this runs too much risk of a tiny initial string holding down a
    82 // huge buffer. This is also tuned to match the extra cost size, so we
    83 // don't ever share a buffer that wouldn't be over the extra cost
    84 // threshold already.
    85 // FIXME: this should be size_t but that would cause warnings until we
    86 // fix UString sizes to be size_t instad of int
    87 static const int minShareSize = Collector::minExtraCostSize / sizeof(UChar);
    88 
    8980COMPILE_ASSERT(sizeof(UChar) == 2, uchar_is_2_bytes)
    9081
     
    174165// Hack here to avoid a global with a constructor; point to an unsigned short instead of a UChar.
    175166static unsigned short almostUChar;
    176 UString::Rep UString::Rep::null = { 0, 0, 1, 0, 0, &UString::Rep::null, 0, 0, 0, 0, 0 };
    177 UString::Rep UString::Rep::empty = { 0, 0, 1, 0, 0, &UString::Rep::empty, reinterpret_cast<UChar*>(&almostUChar), 0, 0, 0, 0 };
     167UString::Rep UString::Rep::null = { 0, 0, 1, 0, 0, &UString::Rep::null, 0, 0, 0, 0, 0, 0 };
     168UString::Rep UString::Rep::empty = { 0, 0, 1, 0, 0, &UString::Rep::empty, 0, reinterpret_cast<UChar*>(&almostUChar), 0, 0, 0, 0 };
    178169const int normalStatBufferSize = 4096;
    179170static char *statBuffer = 0; // FIXME: This buffer is never deallocated.
     
    202193  r->isIdentifier = 0;
    203194  r->baseString = r;
     195  r->reportedCost = 0;
    204196  r->buf = d;
    205197  r->usedCapacity = l;
     
    231223  r->isIdentifier = 0;
    232224  r->baseString = base.releaseRef();
     225  r->reportedCost = 0;
    233226  r->buf = 0;
    234227  r->usedCapacity = 0;
     
    498491    } else
    499492        m_rep = &Rep::null;
    500   } else if (-bOffset == b.usedPreCapacity() && bSize >= minShareSize && 4 * bSize >= aSize) {
     493  } else if (-bOffset == b.usedPreCapacity() && bSize >= minShareSize  && 4 * bSize >= aSize) {
    501494    // - b reaches the beginning of its buffer so it qualifies for shared prepend
    502495    // - also, it's at least a quarter the length of a - prepending to a much shorter
     
    12911284
    12921285
     1286
    12931287} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.