X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/93a3786624b2768d89bfa27e46598dc64e2fb70a..81345200c95645a1b0d2635520f96ad55dfde63f:/runtime/SmallStrings.cpp diff --git a/runtime/SmallStrings.cpp b/runtime/SmallStrings.cpp index 5f35cca..a4bdb0c 100644 --- a/runtime/SmallStrings.cpp +++ b/runtime/SmallStrings.cpp @@ -29,20 +29,13 @@ #include "HeapRootVisitor.h" #include "JSGlobalObject.h" #include "JSString.h" -#include "Operations.h" +#include "JSCInlines.h" #include #include #include namespace JSC { -static inline void finalize(JSString*& string) -{ - if (!string || Heap::isMarked(string)) - return; - string = 0; -} - class SmallStringsStorage { WTF_MAKE_NONCOPYABLE(SmallStringsStorage); WTF_MAKE_FAST_ALLOCATED; public: @@ -65,7 +58,7 @@ SmallStringsStorage::SmallStringsStorage() RefPtr baseString = StringImpl::createUninitialized(singleCharacterStringCount, characterBuffer); for (unsigned i = 0; i < singleCharacterStringCount; ++i) { characterBuffer[i] = i; - m_reps[i] = StringImpl::create(baseString, i, 1); + m_reps[i] = AtomicString::add(PassRefPtr(StringImpl::createSubstringSharingImpl(baseString, i, 1)).get()); } } @@ -74,6 +67,8 @@ SmallStrings::SmallStrings() #define JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE(name) , m_##name(0) JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE) #undef JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE + , m_nullObjectString(nullptr) + , m_undefinedObjectString(nullptr) { COMPILE_ASSERT(singleCharacterStringCount == sizeof(m_singleCharacterStrings) / sizeof(m_singleCharacterStrings[0]), IsNumCharactersConstInSyncWithClassUsage); @@ -84,30 +79,31 @@ SmallStrings::SmallStrings() void SmallStrings::initializeCommonStrings(VM& vm) { createEmptyString(&vm); + for (unsigned i = 0; i <= maxSingleCharacterString; ++i) + createSingleCharacterString(&vm, i); #define JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE(name) initialize(&vm, m_##name, #name); JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE) #undef JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE + initialize(&vm, m_nullObjectString, "[object Null]"); + initialize(&vm, m_undefinedObjectString, "[object Undefined]"); } void SmallStrings::visitStrongReferences(SlotVisitor& visitor) { visitor.appendUnbarrieredPointer(&m_emptyString); + for (unsigned i = 0; i <= maxSingleCharacterString; ++i) + visitor.appendUnbarrieredPointer(m_singleCharacterStrings + i); #define JSC_COMMON_STRINGS_ATTRIBUTE_VISIT(name) visitor.appendUnbarrieredPointer(&m_##name); JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ATTRIBUTE_VISIT) #undef JSC_COMMON_STRINGS_ATTRIBUTE_VISIT + visitor.appendUnbarrieredPointer(&m_nullObjectString); + visitor.appendUnbarrieredPointer(&m_undefinedObjectString); } SmallStrings::~SmallStrings() { } -void SmallStrings::finalizeSmallStrings() -{ - finalize(m_emptyString); - for (unsigned i = 0; i < singleCharacterStringCount; ++i) - finalize(m_singleCharacterStrings[i]); -} - void SmallStrings::createEmptyString(VM* vm) { ASSERT(!m_emptyString);