Ignore:
Timestamp:
Jan 11, 2009, 7:19:23 PM (16 years ago)
Author:
Darin Adler
Message:

2009-01-11 David Levin <[email protected]>

Reviewed by Darin Adler.

https://bugs.webkit.org/show_bug.cgi?id=23175

Separate out BaseString information from UString::Rep and make all baseString access go through
a member function, so that it may be used for something else (in the future) in the BaseString
case.

  • runtime/SmallStrings.cpp: (JSC::SmallStringsStorage::rep): (JSC::SmallStringsStorage::SmallStringsStorage): (JSC::SmallStrings::SmallStrings): (JSC::SmallStrings::mark): Adjust to account for the changes in UString and put the UString in place in SmallStringsStorage to aid in locality of reference among the UChar[] and UString::Rep's.
  • runtime/SmallStrings.h:
  • runtime/UString.cpp: (JSC::initializeStaticBaseString): (JSC::initializeUString): (JSC::UString::Rep::create): (JSC::UString::Rep::destroy): (JSC::UString::Rep::checkConsistency): (JSC::expandCapacity): (JSC::UString::expandPreCapacity): (JSC::concatenate): (JSC::UString::append): (JSC::UString::operator=):
  • runtime/UString.h: (JSC::UString::Rep::baseIsSelf): (JSC::UString::Rep::setBaseString): (JSC::UString::Rep::baseString): (JSC::UString::Rep::): (JSC::UString::Rep::null): (JSC::UString::Rep::empty): (JSC::UString::Rep::data): (JSC::UString::cost): Separate out the items out used by base strings from those used in Rep's that only point to base strings. (This potentially saves 24 bytes per Rep.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/SmallStrings.cpp

    r37938 r39815  
    3030#include "JSString.h"
    3131
     32#include <wtf/Noncopyable.h>
     33
    3234namespace JSC {
     35static const unsigned numCharactersToStore = 0x100;
    3336
    34 class SmallStringsStorage {
     37class SmallStringsStorage : Noncopyable {
    3538public:
    3639    SmallStringsStorage();
    37     ~SmallStringsStorage();
    3840
    39     UString::Rep* rep(unsigned char character) { return &reps[character]; }
     41    UString::Rep* rep(unsigned char character) { return &m_reps[character]; }
    4042
    4143private:
    42     UChar characters[0x100];
    43     UString::Rep* reps;
     44    UChar m_characters[numCharactersToStore];
     45    UString::BaseString m_base;
     46    UString::Rep m_reps[numCharactersToStore];
    4447};
    4548
    4649SmallStringsStorage::SmallStringsStorage()
    47     : reps(static_cast<UString::Rep*>(fastZeroedMalloc(sizeof(UString::Rep) * 0x100)))
    4850{
    49     for (unsigned i = 0; i < 0x100; ++i) {
    50         characters[i] = i;
    51         reps[i].offset = i;
    52         reps[i].len = 1;
    53         reps[i].rc = 1;
    54         reps[i].baseString = &reps[0];
    55     }
    56     reps[0].rc = 0x101;
    57     reps[0].buf = characters;
     51    for (unsigned i = 0; i < numCharactersToStore; ++i)
     52        m_characters[i] = i;
     53
     54    m_base.rc = numCharactersToStore + 1;
     55    m_base.buf = m_characters;
     56    m_base.len = numCharactersToStore;
     57    m_base.offset = 0;
     58    m_base._hash = 0;
     59    m_base.m_baseString = 0;
     60    m_base.preCapacity = 0;
     61    m_base.usedPreCapacity = 0;
     62    m_base.reportedCost = 0;
    5863
    5964    // make sure UString doesn't try to reuse the buffer by pretending we have one more character in it
    60     reps[0].usedCapacity = 0x101;
    61     reps[0].capacity = 0x101;
    62 }
     65    m_base.usedCapacity = numCharactersToStore + 1;
     66    m_base.capacity = numCharactersToStore + 1;
     67    m_base.checkConsistency();
    6368
    64 SmallStringsStorage::~SmallStringsStorage()
    65 {
    66     fastFree(reps);
     69    memset(&m_reps, 0, sizeof(m_reps));
     70    for (unsigned i = 0; i < numCharactersToStore; ++i) {
     71        m_reps[i].offset = i;
     72        m_reps[i].len = 1;
     73        m_reps[i].rc = 1;
     74        m_reps[i].setBaseString(&m_base);
     75        m_reps[i].checkConsistency();
     76    }
    6777}
    6878
     
    7181    , m_storage(0)
    7282{
    73     for (unsigned i = 0; i < 0x100; ++i)
     83    COMPILE_ASSERT(numCharactersToStore == sizeof(m_singleCharacterStrings) / sizeof(m_singleCharacterStrings[0]), IsNumCharactersConstInSyncWithClassUsage);
     84
     85    for (unsigned i = 0; i < numCharactersToStore; ++i)
    7486        m_singleCharacterStrings[i] = 0;
    7587}
     
    8395    if (m_emptyString && !m_emptyString->marked())
    8496        m_emptyString->mark();
    85     for (unsigned i = 0; i < 0x100; ++i) {
     97    for (unsigned i = 0; i < numCharactersToStore; ++i) {
    8698        if (m_singleCharacterStrings[i] && !m_singleCharacterStrings[i]->marked())
    8799            m_singleCharacterStrings[i]->mark();
     
    110122}
    111123
    112 }
     124} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.