#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:
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());
}
}
#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);
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);