Ignore:
Timestamp:
Dec 16, 2008, 6:23:02 PM (16 years ago)
Author:
[email protected]
Message:

2008-12-16 Darin Adler <Darin Adler>

Reviewed and landed by Cameron Zwarich.

Preparatory work for fixing

Bug 22887: Make UString::Rep use RefCounted rather than implementing its own ref counting
<https://bugs.webkit.org/show_bug.cgi?id=22887>

Change the various string translators used by Identifier:add() so that
they never zero the ref count of a newly created UString::Rep. Also,
change similar code for AtomicString to use the same idiomatic style.

JavaScriptCore:

  • runtime/Identifier.cpp: (JSC::CStringTranslator::translate): (JSC::Identifier::add): (JSC::UCharBufferTranslator::translate):

WebCore:

  • platform/text/AtomicString.cpp: (WebCore::AtomicString::add):
File:
1 edited

Legend:

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

    r38528 r39350  
    9797}
    9898
    99 struct CStringTranslator
    100 {
     99struct CStringTranslator {
    101100    static unsigned hash(const char* c)
    102101    {
     
    117116       
    118117        UString::Rep* r = UString::Rep::create(d, static_cast<int>(length)).releaseRef();
    119         r->rc = 0;
    120118        r->_hash = hash;
    121119
     
    144142        return iter->second;
    145143
    146     UString::Rep* addedString = *identifierTable.add<const char*, CStringTranslator>(c).first;
    147     literalIdentifierTable.add(c, addedString);
    148 
    149     return addedString;
     144    pair<HashSet<UString::Rep*>::iterator, bool> addResult = identifierTable.add<const char*, CStringTranslator>(c);
     145
     146    // If the string is newly-translated, then we need to adopt it.
     147    // The boolean in the pair tells us if that is so.
     148    RefPtr<UString::Rep> addedString = addResult.second ? adoptRef(*addResult.first) : *addResult.first;
     149
     150    literalIdentifierTable.add(c, addedString.get());
     151
     152    return addedString.release();
    150153}
    151154
     
    160163};
    161164
    162 struct UCharBufferTranslator
    163 {
     165struct UCharBufferTranslator {
    164166    static unsigned hash(const UCharBuffer& buf)
    165167    {
     
    179181       
    180182        UString::Rep* r = UString::Rep::create(d, buf.length).releaseRef();
    181         r->rc = 0;
    182183        r->_hash = hash;
    183184       
     
    198199    }
    199200    UCharBuffer buf = {s, length};
    200     return *globalData->identifierTable->add<UCharBuffer, UCharBufferTranslator>(buf).first;
     201    pair<HashSet<UString::Rep*>::iterator, bool> addResult = globalData->identifierTable->add<UCharBuffer, UCharBufferTranslator>(buf);
     202
     203    // If the string is newly-translated, then we need to adopt it.
     204    // The boolean in the pair tells us if that is so.
     205    return addResult.second ? adoptRef(*addResult.first) : *addResult.first;
    201206}
    202207
Note: See TracChangeset for help on using the changeset viewer.