]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/SmallStrings.h
JavaScriptCore-1097.13.tar.gz
[apple/javascriptcore.git] / runtime / SmallStrings.h
index bc337c995806d35c1af111c5693760de122d3d54..e609c509221c6ab00d6d578a9f334d1674ed1b1e 100644 (file)
 #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();
@@ -47,6 +63,7 @@ namespace JSC {
                 createEmptyString(globalData);
             return m_emptyString;
         }
+
         JSString* singleCharacterString(JSGlobalData* globalData, unsigned char character)
         {
             if (!m_singleCharacterStrings[character])
@@ -54,21 +71,35 @@ namespace JSC {
             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;
     };