diff options
Diffstat (limited to 'JavaScriptCore/runtime/Identifier.h')
| -rw-r--r-- | JavaScriptCore/runtime/Identifier.h | 160 |
1 files changed, 50 insertions, 110 deletions
diff --git a/JavaScriptCore/runtime/Identifier.h b/JavaScriptCore/runtime/Identifier.h index 1d1bd18..3a8aed7 100644 --- a/JavaScriptCore/runtime/Identifier.h +++ b/JavaScriptCore/runtime/Identifier.h @@ -24,6 +24,7 @@ #include "JSGlobalData.h" #include "ThreadSpecific.h" #include "UString.h" +#include <wtf/text/CString.h> namespace JSC { @@ -34,38 +35,37 @@ namespace JSC { public: Identifier() { } - Identifier(ExecState* exec, const char* s) : _ustring(add(exec, s)) { } // Only to be used with string literals. - Identifier(ExecState* exec, const UChar* s, int length) : _ustring(add(exec, s, length)) { } - Identifier(ExecState* exec, UString::Rep* rep) : _ustring(add(exec, rep)) { } - Identifier(ExecState* exec, const UString& s) : _ustring(add(exec, s.rep())) { } + Identifier(ExecState* exec, const char* s) : m_string(add(exec, s)) { } // Only to be used with string literals. + Identifier(ExecState* exec, const UChar* s, int length) : m_string(add(exec, s, length)) { } + Identifier(ExecState* exec, StringImpl* rep) : m_string(add(exec, rep)) { } + Identifier(ExecState* exec, const UString& s) : m_string(add(exec, s.impl())) { } - Identifier(JSGlobalData* globalData, const char* s) : _ustring(add(globalData, s)) { } // Only to be used with string literals. - Identifier(JSGlobalData* globalData, const UChar* s, int length) : _ustring(add(globalData, s, length)) { } - Identifier(JSGlobalData* globalData, UString::Rep* rep) : _ustring(add(globalData, rep)) { } - Identifier(JSGlobalData* globalData, const UString& s) : _ustring(add(globalData, s.rep())) { } + Identifier(JSGlobalData* globalData, const char* s) : m_string(add(globalData, s)) { } // Only to be used with string literals. + Identifier(JSGlobalData* globalData, const UChar* s, int length) : m_string(add(globalData, s, length)) { } + Identifier(JSGlobalData* globalData, StringImpl* rep) : m_string(add(globalData, rep)) { } + Identifier(JSGlobalData* globalData, const UString& s) : m_string(add(globalData, s.impl())) { } - // Special constructor for cases where we overwrite an object in place. - Identifier(PlacementNewAdoptType) : _ustring(PlacementNewAdopt) { } + const UString& ustring() const { return m_string; } + StringImpl* impl() const { return m_string.impl(); } - const UString& ustring() const { return _ustring; } + const UChar* characters() const { return m_string.characters(); } + int length() const { return m_string.length(); } - const UChar* data() const { return _ustring.data(); } - int size() const { return _ustring.size(); } + CString ascii() const { return m_string.ascii(); } - const char* ascii() const { return _ustring.ascii(); } - - static Identifier from(ExecState* exec, unsigned y) { return Identifier(exec, UString::from(y)); } - static Identifier from(ExecState* exec, int y) { return Identifier(exec, UString::from(y)); } - static Identifier from(ExecState* exec, double y) { return Identifier(exec, UString::from(y)); } - - bool isNull() const { return _ustring.isNull(); } - bool isEmpty() const { return _ustring.isEmpty(); } - - uint32_t toUInt32(bool* ok) const { return _ustring.toUInt32(ok); } - uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const { return _ustring.toUInt32(ok, tolerateEmptyString); }; - uint32_t toStrictUInt32(bool* ok) const { return _ustring.toStrictUInt32(ok); } - unsigned toArrayIndex(bool* ok) const { return _ustring.toArrayIndex(ok); } - double toDouble() const { return _ustring.toDouble(); } + static Identifier from(ExecState* exec, unsigned y); + static Identifier from(ExecState* exec, int y); + static Identifier from(ExecState* exec, double y); + static Identifier from(JSGlobalData*, unsigned y); + static Identifier from(JSGlobalData*, int y); + static Identifier from(JSGlobalData*, double y); + + static uint32_t toUInt32(const UString&, bool& ok); + uint32_t toUInt32(bool& ok) const { return toUInt32(m_string, ok); } + unsigned toArrayIndex(bool& ok) const; + + bool isNull() const { return m_string.isNull(); } + bool isEmpty() const { return m_string.isEmpty(); } friend bool operator==(const Identifier&, const Identifier&); friend bool operator!=(const Identifier&, const Identifier&); @@ -73,50 +73,46 @@ namespace JSC { friend bool operator==(const Identifier&, const char*); friend bool operator!=(const Identifier&, const char*); - static void remove(UString::Rep*); - - static bool equal(const UString::Rep*, const char*); - static bool equal(const UString::Rep*, const UChar*, int length); - static bool equal(const UString::Rep* a, const UString::Rep* b) { return JSC::equal(a, b); } + static bool equal(const StringImpl*, const char*); + static bool equal(const StringImpl*, const UChar*, unsigned length); + static bool equal(const StringImpl* a, const StringImpl* b) { return ::equal(a, b); } - static PassRefPtr<UString::Rep> add(ExecState*, const char*); // Only to be used with string literals. - static PassRefPtr<UString::Rep> add(JSGlobalData*, const char*); // Only to be used with string literals. + static PassRefPtr<StringImpl> add(ExecState*, const char*); // Only to be used with string literals. + static PassRefPtr<StringImpl> add(JSGlobalData*, const char*); // Only to be used with string literals. private: - UString _ustring; + UString m_string; - static bool equal(const Identifier& a, const Identifier& b) { return a._ustring.rep() == b._ustring.rep(); } - static bool equal(const Identifier& a, const char* b) { return equal(a._ustring.rep(), b); } + static bool equal(const Identifier& a, const Identifier& b) { return a.m_string.impl() == b.m_string.impl(); } + static bool equal(const Identifier& a, const char* b) { return equal(a.m_string.impl(), b); } - static PassRefPtr<UString::Rep> add(ExecState*, const UChar*, int length); - static PassRefPtr<UString::Rep> add(JSGlobalData*, const UChar*, int length); + static PassRefPtr<StringImpl> add(ExecState*, const UChar*, int length); + static PassRefPtr<StringImpl> add(JSGlobalData*, const UChar*, int length); - static PassRefPtr<UString::Rep> add(ExecState* exec, UString::Rep* r) + static PassRefPtr<StringImpl> add(ExecState* exec, StringImpl* r) { - if (r->isIdentifier()) { #ifndef NDEBUG - checkSameIdentifierTable(exec, r); + checkCurrentIdentifierTable(exec); #endif + if (r->isIdentifier()) return r; - } return addSlowCase(exec, r); } - static PassRefPtr<UString::Rep> add(JSGlobalData* globalData, UString::Rep* r) + static PassRefPtr<StringImpl> add(JSGlobalData* globalData, StringImpl* r) { - if (r->isIdentifier()) { #ifndef NDEBUG - checkSameIdentifierTable(globalData, r); + checkCurrentIdentifierTable(globalData); #endif + if (r->isIdentifier()) return r; - } return addSlowCase(globalData, r); } - static PassRefPtr<UString::Rep> addSlowCase(ExecState*, UString::Rep* r); - static PassRefPtr<UString::Rep> addSlowCase(JSGlobalData*, UString::Rep* r); + static PassRefPtr<StringImpl> addSlowCase(ExecState*, StringImpl* r); + static PassRefPtr<StringImpl> addSlowCase(JSGlobalData*, StringImpl* r); - static void checkSameIdentifierTable(ExecState*, UString::Rep*); - static void checkSameIdentifierTable(JSGlobalData*, UString::Rep*); + static void checkCurrentIdentifierTable(ExecState*); + static void checkCurrentIdentifierTable(JSGlobalData*); }; inline bool operator==(const Identifier& a, const Identifier& b) @@ -142,67 +138,11 @@ namespace JSC { IdentifierTable* createIdentifierTable(); void deleteIdentifierTable(IdentifierTable*); - struct ThreadIdentifierTableData { - ThreadIdentifierTableData() - : defaultIdentifierTable(0) - , currentIdentifierTable(0) - { - } - - IdentifierTable* defaultIdentifierTable; - IdentifierTable* currentIdentifierTable; + struct IdentifierRepHash : PtrHash<RefPtr<StringImpl> > { + static unsigned hash(const RefPtr<StringImpl>& key) { return key->existingHash(); } + static unsigned hash(StringImpl* key) { return key->existingHash(); } }; - extern WTF::ThreadSpecific<ThreadIdentifierTableData>* g_identifierTableSpecific; - void createIdentifierTableSpecific(); - - inline IdentifierTable* defaultIdentifierTable() - { - if (!g_identifierTableSpecific) - createIdentifierTableSpecific(); - ThreadIdentifierTableData& data = **g_identifierTableSpecific; - - return data.defaultIdentifierTable; - } - - inline void setDefaultIdentifierTable(IdentifierTable* identifierTable) - { - if (!g_identifierTableSpecific) - createIdentifierTableSpecific(); - ThreadIdentifierTableData& data = **g_identifierTableSpecific; - - data.defaultIdentifierTable = identifierTable; - } - - inline IdentifierTable* currentIdentifierTable() - { - if (!g_identifierTableSpecific) - createIdentifierTableSpecific(); - ThreadIdentifierTableData& data = **g_identifierTableSpecific; - - return data.currentIdentifierTable; - } - - inline IdentifierTable* setCurrentIdentifierTable(IdentifierTable* identifierTable) - { - if (!g_identifierTableSpecific) - createIdentifierTableSpecific(); - ThreadIdentifierTableData& data = **g_identifierTableSpecific; - - IdentifierTable* oldIdentifierTable = data.currentIdentifierTable; - data.currentIdentifierTable = identifierTable; - return oldIdentifierTable; - } - - inline void resetCurrentIdentifierTable() - { - if (!g_identifierTableSpecific) - createIdentifierTableSpecific(); - ThreadIdentifierTableData& data = **g_identifierTableSpecific; - - data.currentIdentifierTable = data.defaultIdentifierTable; - } - } // namespace JSC #endif // Identifier_h |
