]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/SmallStrings.cpp
JavaScriptCore-7600.1.4.9.tar.gz
[apple/javascriptcore.git] / runtime / SmallStrings.cpp
index 5f35cca5e2cd78cb462462f8ade59e399079fe13..a4bdb0c9e3cbfbacf58ed281957f0adf6a8794b1 100644 (file)
 #include "HeapRootVisitor.h"
 #include "JSGlobalObject.h"
 #include "JSString.h"
-#include "Operations.h"
+#include "JSCInlines.h"
 #include <wtf/Noncopyable.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/text/StringImpl.h>
 
 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<StringImpl> 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>(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);