]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/SmallStrings.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / SmallStrings.cpp
index a4bdb0c9e3cbfbacf58ed281957f0adf6a8794b1..9c6a43ae2138f4eefeba6e1d02bc2ead19e4de51 100644 (file)
@@ -31,7 +31,6 @@
 #include "JSString.h"
 #include "JSCInlines.h"
 #include <wtf/Noncopyable.h>
-#include <wtf/PassOwnPtr.h>
 #include <wtf/text/StringImpl.h>
 
 namespace JSC {
@@ -58,7 +57,7 @@ SmallStringsStorage::SmallStringsStorage()
     RefPtr<StringImpl> baseString = StringImpl::createUninitialized(singleCharacterStringCount, characterBuffer);
     for (unsigned i = 0; i < singleCharacterStringCount; ++i) {
         characterBuffer[i] = i;
-        m_reps[i] = AtomicString::add(PassRefPtr<StringImpl>(StringImpl::createSubstringSharingImpl(baseString, i, 1)).get());
+        m_reps[i] = AtomicStringImpl::add(PassRefPtr<StringImpl>(StringImpl::createSubstringSharingImpl(baseString, i, 1)).get());
     }
 }
 
@@ -69,6 +68,7 @@ SmallStrings::SmallStrings()
 #undef JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE
     , m_nullObjectString(nullptr)
     , m_undefinedObjectString(nullptr)
+    , m_needsToBeVisited(true)
 {
     COMPILE_ASSERT(singleCharacterStringCount == sizeof(m_singleCharacterStrings) / sizeof(m_singleCharacterStrings[0]), IsNumCharactersConstInSyncWithClassUsage);
 
@@ -90,6 +90,7 @@ void SmallStrings::initializeCommonStrings(VM& vm)
 
 void SmallStrings::visitStrongReferences(SlotVisitor& visitor)
 {
+    m_needsToBeVisited = false;
     visitor.appendUnbarrieredPointer(&m_emptyString);
     for (unsigned i = 0; i <= maxSingleCharacterString; ++i)
         visitor.appendUnbarrieredPointer(m_singleCharacterStrings + i);
@@ -108,26 +109,29 @@ void SmallStrings::createEmptyString(VM* vm)
 {
     ASSERT(!m_emptyString);
     m_emptyString = JSString::createHasOtherOwner(*vm, StringImpl::empty());
+    m_needsToBeVisited = true;
 }
 
 void SmallStrings::createSingleCharacterString(VM* vm, unsigned char character)
 {
     if (!m_storage)
-        m_storage = adoptPtr(new SmallStringsStorage);
+        m_storage = std::make_unique<SmallStringsStorage>();
     ASSERT(!m_singleCharacterStrings[character]);
     m_singleCharacterStrings[character] = JSString::createHasOtherOwner(*vm, PassRefPtr<StringImpl>(m_storage->rep(character)));
+    m_needsToBeVisited = true;
 }
 
 StringImpl* SmallStrings::singleCharacterStringRep(unsigned char character)
 {
     if (!m_storage)
-        m_storage = adoptPtr(new SmallStringsStorage);
+        m_storage = std::make_unique<SmallStringsStorage>();
     return m_storage->rep(character);
 }
 
-void SmallStrings::initialize(VM* vm, JSString*& string, const char* value) const
+void SmallStrings::initialize(VM* vm, JSString*& string, const char* value)
 {
-    string = JSString::create(*vm, StringImpl::create(value));
+    string = JSString::create(*vm, Identifier::fromString(vm, value).impl());
+    m_needsToBeVisited = true;
 }
 
 } // namespace JSC