Ignore:
Timestamp:
Mar 12, 2010, 3:49:05 PM (15 years ago)
Author:
[email protected]
Message:

Bug 36075 - Clean up screwyness re static string impls & Identifiers.

Reviewed by Oliver Hunt.

JavaScriptCore:

  • API/JSClassRef.cpp:

(OpaqueJSClass::~OpaqueJSClass): Classname may be null/empty, and these are an identifer. This is okay, since the null/empty strings are shared across all threads.

(JSC::Identifier::add): No need to explicitly hash null reps, this is done in the ststic UStringImpl constructor.
(JSC::Identifier::addSlowCase): UStringImpl::empty() handled & checkCurrentIdentifierTable now called in the header.
(JSC::Identifier::checkCurrentIdentifierTable): Replaces checkSameIdentifierTable (this no longer checked the rep since the identifierTable pointer was removed from UString::Rep long ago).

  • runtime/Identifier.h:

(JSC::Identifier::add): Replace call to checkSameIdentifierTable with call to checkCurrentIdentifierTable at head of function.

  • runtime/UStringImpl.cpp:

(JSC::UStringImpl::~UStringImpl): Remove call to checkConsistency - this function no longer checks anything interesting.

  • runtime/UStringImpl.h:

(JSC::UStringOrRopeImpl::UStringOrRopeImpl): Set s_refCountFlagIsIdentifier in static constructor.
(JSC::UStringImpl::UStringImpl): remove calls to checkConsistency (see above), add new ASSERT to substring constructor.
(JSC::UStringImpl::setHash): ASSERT not static (static strings set the hash in their constructor, should not reach this code path).
(JSC::UStringImpl::create): Add missing ASSERT.
(JSC::UStringImpl::setIsIdentifier): ASSERT !isStatic() (static strings hash set in constructor).

WebCore:

  • platform/text/StringImpl.cpp:

(WebCore::StringImpl::~StringImpl): Add ASSERT
(WebCore::StringImpl::sharedBuffer): Add ASSERT

  • platform/text/StringImpl.h:

(WebCore::StringImpl::setHash): Add ASSERT
(WebCore::StringImpl::isStatic): added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/UStringImpl.h

    r55881 r55943  
    7373    enum StaticStringConstructType { ConstructStaticString };
    7474    UStringOrRopeImpl(unsigned length, StaticStringConstructType)
    75         : m_refCountAndFlags(s_refCountFlagStatic | BufferOwned)
     75        : m_refCountAndFlags(s_refCountFlagStatic | s_refCountFlagIsIdentifier | BufferOwned)
    7676        , m_length(length)
    7777    {
     
    126126    {
    127127        hash();
    128         checkConsistency();
    129128    }
    130129
     
    138137        ASSERT(m_data);
    139138        ASSERT(m_length);
    140         checkConsistency();
    141139    }
    142140
     
    150148        ASSERT(m_data);
    151149        ASSERT(m_length);
    152         checkConsistency();
    153150    }
    154151
     
    162159        ASSERT(m_data);
    163160        ASSERT(m_length);
    164         checkConsistency();
     161        ASSERT(m_substringBuffer->bufferOwnership() != BufferSubstring);
    165162    }
    166163
     
    174171        ASSERT(m_data);
    175172        ASSERT(m_length);
    176         checkConsistency();
    177173    }
    178174
     
    180176    void setHash(unsigned hash)
    181177    {
     178        ASSERT(!isStatic());
    182179        ASSERT(!m_hash);
    183180        ASSERT(hash == computeHash(m_data, m_length));
     
    194191    static PassRefPtr<UStringImpl> create(PassRefPtr<UStringImpl> rep, unsigned offset, unsigned length)
    195192    {
     193        ASSERT(rep);
     194        ASSERT(length <= rep->length());
     195
    196196        if (!length)
    197197            return empty();
    198         ASSERT(rep);
    199         rep->checkConsistency();
     198
    200199        UStringImpl* ownerRep = (rep->bufferOwnership() == BufferSubstring) ? rep->m_substringBuffer : rep.get();
    201200        return adoptRef(new UStringImpl(rep->m_data + offset, length, ownerRep));
     
    248247    void setIsIdentifier(bool isIdentifier)
    249248    {
     249        ASSERT(!isStatic());
    250250        if (isIdentifier)
    251251            m_refCountAndFlags |= s_refCountFlagIsIdentifier;
     
    273273    }
    274274
    275     ALWAYS_INLINE void checkConsistency() const
    276     {
    277         // There is no recursion of substrings.
    278         ASSERT((bufferOwnership() != BufferSubstring) || (m_substringBuffer->bufferOwnership() != BufferSubstring));
    279         // Static strings cannot be put in identifier tables, because they are globally shared.
    280         ASSERT(!isStatic() || !isIdentifier());
    281     }
    282 
    283275private:
    284276    // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
     
    288280    bool isStatic() const { return m_refCountAndFlags & s_refCountFlagStatic; }
    289281
    290     // unshared data
    291282    const UChar* m_data;
    292283    union {
Note: See TracChangeset for help on using the changeset viewer.