X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/93a3786624b2768d89bfa27e46598dc64e2fb70a..2656c66b5b30d5597e842a751c7f19ad6c2fe31a:/runtime/Identifier.h diff --git a/runtime/Identifier.h b/runtime/Identifier.h index f075aa6..50a253f 100644 --- a/runtime/Identifier.h +++ b/runtime/Identifier.h @@ -36,29 +36,36 @@ namespace JSC { public: Identifier() { } enum EmptyIdentifierFlag { EmptyIdentifier }; - Identifier(EmptyIdentifierFlag) : m_string(StringImpl::empty()) { } + Identifier(EmptyIdentifierFlag) : m_string(StringImpl::empty()) { ASSERT(m_string.impl()->isAtomic()); } // Only to be used with string literals. template - Identifier(ExecState* exec, const char (&characters)[charactersCount]) : m_string(add(exec, characters)) { } + Identifier(ExecState* exec, const char (&characters)[charactersCount]) : m_string(add(exec, characters)) { ASSERT(m_string.impl()->isAtomic()); } template - Identifier(VM* vm, const char (&characters)[charactersCount]) : m_string(add(vm, characters)) { } + Identifier(VM* vm, const char (&characters)[charactersCount]) : m_string(add(vm, characters)) { ASSERT(m_string.impl()->isAtomic()); } - Identifier(ExecState* exec, StringImpl* rep) : m_string(add(exec, rep)) { } - Identifier(ExecState* exec, const String& s) : m_string(add(exec, s.impl())) { } + Identifier(ExecState* exec, StringImpl* rep) : m_string(add(exec, rep)) { ASSERT(m_string.impl()->isAtomic()); } + Identifier(ExecState* exec, const String& s) : m_string(add(exec, s.impl())) { ASSERT(m_string.impl()->isAtomic()); } - Identifier(VM* vm, const LChar* s, int length) : m_string(add(vm, s, length)) { } - Identifier(VM* vm, const UChar* s, int length) : m_string(add(vm, s, length)) { } - Identifier(VM* vm, StringImpl* rep) : m_string(add(vm, rep)) { } - Identifier(VM* vm, const String& s) : m_string(add(vm, s.impl())) { } + Identifier(VM* vm, const LChar* s, int length) : m_string(add(vm, s, length)) { ASSERT(m_string.impl()->isAtomic()); } + Identifier(VM* vm, const UChar* s, int length) : m_string(add(vm, s, length)) { ASSERT(m_string.impl()->isAtomic()); } + Identifier(VM* vm, StringImpl* rep) : m_string(add(vm, rep)) { ASSERT(m_string.impl()->isAtomic()); } + Identifier(VM* vm, const String& s) : m_string(add(vm, s.impl())) { ASSERT(m_string.impl()->isAtomic()); } const String& string() const { return m_string; } StringImpl* impl() const { return m_string.impl(); } - const UChar* characters() const { return m_string.characters(); } int length() const { return m_string.length(); } CString ascii() const { return m_string.ascii(); } + CString utf8() const { return m_string.utf8(); } + + static Identifier from(const PrivateName& name) + { + Identifier result; + result.m_string = name.uid(); + return result; + } static Identifier createLCharFromUChar(VM* vm, const UChar* s, int length) { return Identifier(vm, add8(vm, s, length)); } @@ -87,8 +94,8 @@ namespace JSC { static bool equal(const StringImpl* a, const StringImpl* b) { return ::equal(a, b); } // Only to be used with string literals. - static PassRefPtr add(VM*, const char*); - JS_EXPORT_PRIVATE static PassRefPtr add(ExecState*, const char*); + JS_EXPORT_PRIVATE static PassRef add(VM*, const char*); + JS_EXPORT_PRIVATE static PassRef add(ExecState*, const char*); private: String m_string; @@ -99,34 +106,15 @@ namespace JSC { 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 LChar* b) { return equal(a.m_string.impl(), b); } - template static PassRefPtr add(VM*, const T*, int length); - static PassRefPtr add8(VM*, const UChar*, int length); + template static PassRef add(VM*, const T*, int length); + static PassRef add8(VM*, const UChar*, int length); template ALWAYS_INLINE static bool canUseSingleCharacterString(T); - static PassRefPtr add(ExecState* exec, StringImpl* r) - { -#ifndef NDEBUG - checkCurrentIdentifierTable(exec); -#endif - if (r->isIdentifier()) - return r; - return addSlowCase(exec, r); - } - static PassRefPtr add(VM* vm, StringImpl* r) - { -#ifndef NDEBUG - checkCurrentIdentifierTable(vm); -#endif - if (r->isIdentifier()) - return r; - return addSlowCase(vm, r); - } - - JS_EXPORT_PRIVATE static PassRefPtr addSlowCase(ExecState*, StringImpl* r); - JS_EXPORT_PRIVATE static PassRefPtr addSlowCase(VM*, StringImpl* r); + static PassRef add(ExecState*, StringImpl*); + static PassRef add(VM*, StringImpl*); - JS_EXPORT_PRIVATE static void checkCurrentIdentifierTable(ExecState*); - JS_EXPORT_PRIVATE static void checkCurrentIdentifierTable(VM*); + JS_EXPORT_PRIVATE static void checkCurrentAtomicStringTable(ExecState*); + JS_EXPORT_PRIVATE static void checkCurrentAtomicStringTable(VM*); }; template <> ALWAYS_INLINE bool Identifier::canUseSingleCharacterString(LChar) @@ -141,51 +129,17 @@ namespace JSC { } template - struct CharBuffer { - const T* s; - unsigned int length; - }; - - template - struct IdentifierCharBufferTranslator { - static unsigned hash(const CharBuffer& buf) - { - return StringHasher::computeHashAndMaskTop8Bits(buf.s, buf.length); - } - - static bool equal(StringImpl* str, const CharBuffer& buf) - { - return Identifier::equal(str, buf.s, buf.length); - } - - static void translate(StringImpl*& location, const CharBuffer& buf, unsigned hash) - { - T* d; - StringImpl* r = StringImpl::createUninitialized(buf.length, d).leakRef(); - for (unsigned i = 0; i != buf.length; i++) - d[i] = buf.s[i]; - r->setHash(hash); - location = r; - } - }; - - template - PassRefPtr Identifier::add(VM* vm, const T* s, int length) + PassRef Identifier::add(VM* vm, const T* s, int length) { if (length == 1) { T c = s[0]; if (canUseSingleCharacterString(c)) - return add(vm, vm->smallStrings.singleCharacterStringRep(c)); + return *vm->smallStrings.singleCharacterStringRep(c); } - if (!length) - return StringImpl::empty(); - CharBuffer buf = { s, static_cast(length) }; - HashSet::AddResult addResult = vm->identifierTable->add, IdentifierCharBufferTranslator >(buf); + return *StringImpl::empty(); - // If the string is newly-translated, then we need to adopt it. - // The boolean in the pair tells us if that is so. - return addResult.isNewEntry ? adoptRef(*addResult.iterator) : *addResult.iterator; + return *AtomicString::add(s, length); } inline bool operator==(const Identifier& a, const Identifier& b) @@ -233,10 +187,7 @@ namespace JSC { return WTF::equal(r, s, length); } - IdentifierTable* createIdentifierTable(); - void deleteIdentifierTable(IdentifierTable*); - - struct IdentifierRepHash : PtrHash > { + struct IdentifierRepHash : PtrHash> { static unsigned hash(const RefPtr& key) { return key->existingHash(); } static unsigned hash(StringImpl* key) { return key->existingHash(); } }; @@ -246,15 +197,8 @@ namespace JSC { static const bool emptyValueIsZero = false; }; - typedef HashMap, int, IdentifierRepHash, HashTraits >, IdentifierMapIndexHashTraits> IdentifierMap; - - template - HashSet::AddResult IdentifierTable::add(U value) - { - HashSet::AddResult result = m_table.add(value); - (*result.iterator)->setIsIdentifier(true); - return result; - } + typedef HashMap, int, IdentifierRepHash, HashTraits>, IdentifierMapIndexHashTraits> IdentifierMap; + typedef HashMap, IdentifierMapIndexHashTraits> BorrowedIdentifierMap; } // namespace JSC