Ignore:
Timestamp:
Apr 22, 2010, 1:31:04 PM (15 years ago)
Author:
[email protected]
Message:

https://bugs.webkit.org/show_bug.cgi?id=37978
Unify JSC::IdentifierTable and WebCore::AtomicStringTable implementations.

Reviewed by Geoff Garen.

These two classes both implement a HashSet of uniqued StringImpls, with
translator classes to avoid unnecessary object creation. The only difference
between the classes is which flag (isIdentifier or inTable) is set.
Combine the two classes using a template predicated on which flag to use.

New class AtomicStringTable created, containing all the goodness from
IdentifierTable & AtomicStringTable, expect for Identifier's literalTable,
which has been moved onto JSGlobalData. Removed duplicate string translator
classes. Renamed StringImpl's inTable flag to more explicit 'isAtomic',
and set this on the empty string (which matches Identifier behaviour, and
removes a redundant check for zero-length).

(JSC::createLiteralTable):
(JSC::deleteLiteralTable):
(JSC::Identifier::add):
(JSC::Identifier::addSlowCase):

  • runtime/Identifier.h:
  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::~JSGlobalData):

  • runtime/JSGlobalData.h:
  • wtf/WTFThreadData.cpp:

(WTF::WTFThreadData::WTFThreadData):
(WTF::WTFThreadData::~WTFThreadData):

  • wtf/WTFThreadData.h:

(WTF::WTFThreadData::atomicStringTable):

  • wtf/text/AtomicString.cpp:

(WebCore::table):
(WebCore::operator==):
(WebCore::AtomicString::add):
(WebCore::AtomicString::find):
(WebCore::AtomicString::remove):

  • wtf/text/AtomicStringTable.h: Added.

(WTF::CStringTranslator::hash):
(WTF::CStringTranslator::equal):
(WTF::CStringTranslator::translate):
(WTF::UCharBufferTranslator::hash):
(WTF::UCharBufferTranslator::equal):
(WTF::UCharBufferTranslator::translate):
(WTF::HashAndCharactersTranslator::hash):
(WTF::HashAndCharactersTranslator::equal):
(WTF::HashAndCharactersTranslator::translate):
(WTF::IdentifierOrAtomicStringTable::remove):
(WTF::::~IdentifierOrAtomicStringTable):
(WTF::::add):
(WTF::::find):

  • wtf/text/StringImpl.cpp:

(WebCore::StringImpl::~StringImpl):

  • wtf/text/StringImpl.h:

(WebCore::StringImpl::isAtomic):
(WebCore::StringImpl::setIsAtomic):
(WebCore::equal):

  • wtf/text/StringImplBase.h:

(WTF::StringImplBase::StringImplBase):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/WTFThreadData.h

    r58003 r58114  
    2828#define WTFThreadData_h
    2929
    30 #include <wtf/HashMap.h>
    31 #include <wtf/HashSet.h>
    3230#include <wtf/Noncopyable.h>
    33 #include <wtf/text/StringHash.h>
    3431
    3532// This was ENABLE(WORKERS) in WebCore, but this is not defined when compiling JSC.
     
    4744
    4845// FIXME: This is a temporary layering violation while we move more string code to WTF.
     46namespace JSC {
     47class IdentifierTable;
     48}
     49
     50// FIXME: This is a temporary layering violation while we move more string code to WTF.
    4951namespace WebCore {
    5052class AtomicStringTable;
    51 class StringImpl;
    5253}
    53 using WebCore::StringImpl;
    54 
    55 typedef void (*AtomicStringTableDestructor)(WebCore::AtomicStringTable*);
    56 
    57 #if USE(JSC)
    58 // FIXME: This is a temporary layering violation while we move more string code to WTF.
    59 namespace JSC {
    60 
    61 typedef HashMap<const char*, RefPtr<StringImpl>, PtrHash<const char*> > LiteralIdentifierTable;
    62 
    63 class IdentifierTable : public FastAllocBase {
    64 public:
    65     ~IdentifierTable();
    66 
    67     std::pair<HashSet<StringImpl*>::iterator, bool> add(StringImpl* value);
    68     template<typename U, typename V>
    69     std::pair<HashSet<StringImpl*>::iterator, bool> add(U value);
    70 
    71     void remove(StringImpl* r) { m_table.remove(r); }
    72 
    73     LiteralIdentifierTable& literalTable() { return m_literalTable; }
    74 
    75 private:
    76     HashSet<StringImpl*> m_table;
    77     LiteralIdentifierTable m_literalTable;
    78 };
    79 
    80 }
    81 #endif
    8254
    8355namespace WTF {
     
    8860    ~WTFThreadData();
    8961
    90     WebCore::AtomicStringTable* atomicStringTable()
     62    WebCore::AtomicStringTable& atomicStringTable()
    9163    {
    92         return m_atomicStringTable;
     64        return *m_atomicStringTable;
    9365    }
    9466
     
    12092private:
    12193    WebCore::AtomicStringTable* m_atomicStringTable;
    122     AtomicStringTableDestructor m_atomicStringTableDestructor;
    12394
    12495#if USE(JSC)
     
    133104#endif
    134105    friend WTFThreadData& wtfThreadData();
    135     friend class WebCore::AtomicStringTable;
    136106};
    137107
Note: See TracChangeset for help on using the changeset viewer.