#define SmallStrings_h
#include "UString.h"
+#include <wtf/FixedArray.h>
#include <wtf/OwnPtr.h>
+#define JSC_COMMON_STRINGS_EACH_NAME(macro) \
+ macro(boolean) \
+ macro(false) \
+ macro(function) \
+ macro(number) \
+ macro(null) \
+ macro(object) \
+ macro(undefined) \
+ macro(string) \
+ macro(true)
+
namespace JSC {
+ class HeapRootVisitor;
class JSGlobalData;
class JSString;
- class MarkStack;
class SmallStringsStorage;
+ class SlotVisitor;
+
+ static const unsigned maxSingleCharacterString = 0xFF;
- class SmallStrings : public Noncopyable {
+ class SmallStrings {
+ WTF_MAKE_NONCOPYABLE(SmallStrings);
public:
SmallStrings();
~SmallStrings();
createEmptyString(globalData);
return m_emptyString;
}
+
JSString* singleCharacterString(JSGlobalData* globalData, unsigned char character)
{
if (!m_singleCharacterStrings[character])
return m_singleCharacterStrings[character];
}
- UString::Rep* singleCharacterStringRep(unsigned char character);
+ JS_EXPORT_PRIVATE StringImpl* singleCharacterStringRep(unsigned char character);
+
+ void finalizeSmallStrings();
- void markChildren(MarkStack&);
- void clear();
+ JSString** singleCharacterStrings() { return &m_singleCharacterStrings[0]; }
+
+#define JSC_COMMON_STRINGS_ACCESSOR_DEFINITION(name) \
+ JSString* name##String(JSGlobalData* globalData) const \
+ { \
+ if (!m_##name) \
+ initialize(globalData, m_##name, #name); \
+ return m_##name; \
+ }
+ JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ACCESSOR_DEFINITION)
+#undef JSC_COMMON_STRINGS_ACCESSOR_DEFINITION
- unsigned count() const;
-#if ENABLE(JIT)
- JSString** singleCharacterStrings() { return m_singleCharacterStrings; }
-#endif
private:
- void createEmptyString(JSGlobalData*);
- void createSingleCharacterString(JSGlobalData*, unsigned char);
+ static const unsigned singleCharacterStringCount = maxSingleCharacterString + 1;
+
+ JS_EXPORT_PRIVATE void createEmptyString(JSGlobalData*);
+ JS_EXPORT_PRIVATE void createSingleCharacterString(JSGlobalData*, unsigned char);
+
+ void initialize(JSGlobalData* globalData, JSString*& string, const char* value) const;
JSString* m_emptyString;
- JSString* m_singleCharacterStrings[0x100];
+#define JSC_COMMON_STRINGS_ATTRIBUTE_DECLARATION(name) mutable JSString* m_##name;
+ JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ATTRIBUTE_DECLARATION)
+#undef JSC_COMMON_STRINGS_ATTRIBUTE_DECLARATION
+ JSString* m_singleCharacterStrings[singleCharacterStringCount];
OwnPtr<SmallStringsStorage> m_storage;
};