]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/RegExpCache.h
JavaScriptCore-903.5.tar.gz
[apple/javascriptcore.git] / runtime / RegExpCache.h
index 998d80bc0c9a3ff0cc38779a501f8cb18a5e9781..4f3ea1536a4eae10d9dcbeb794ecd7510c2a61f6 100644 (file)
 
 #include "RegExp.h"
 #include "RegExpKey.h"
+#include "Strong.h"
 #include "UString.h"
+#include "Weak.h"
+#include <wtf/FixedArray.h>
+#include <wtf/HashMap.h>
 
 #ifndef RegExpCache_h
 #define RegExpCache_h
 
 namespace JSC {
 
-class RegExpCache {
+class RegExpCache : private WeakHandleOwner {
+friend class RegExp;
+typedef HashMap<RegExpKey, Weak<RegExp> > RegExpCacheMap;
+
 public:
-    PassRefPtr<RegExp> lookupOrCreate(const UString& patternString, const UString& flags);
-    PassRefPtr<RegExp> create(const UString& patternString, const UString& flags);
     RegExpCache(JSGlobalData* globalData);
-    
-    static bool isCacheable(const UString& patternString) { return patternString.size() < maxCacheablePatternLength; }
+    void invalidateCode();
 
 private:
-    static const unsigned maxCacheablePatternLength = 256;
-    static const int maxCacheableEntries = 32;
+    
+    static const unsigned maxStrongCacheablePatternLength = 256;
+
+    static const int maxStrongCacheableEntries = 32;
+
+    virtual void finalize(Handle<Unknown>, void* context);
 
-    typedef HashMap<RegExpKey, RefPtr<RegExp> > RegExpCacheMap;
-    RegExpKey patternKeyArray[maxCacheableEntries];
-    RegExpCacheMap m_cacheMap;
+    RegExp* lookupOrCreate(const UString& patternString, RegExpFlags);
+    void addToStrongCache(RegExp*);
+    RegExpCacheMap m_weakCache; // Holds all regular expressions currently live.
+    int m_nextEntryInStrongCache;
+    WTF::FixedArray<Strong<RegExp>, maxStrongCacheableEntries> m_strongCache; // Holds a select few regular expressions that have compiled and executed
     JSGlobalData* m_globalData;
-    int m_nextKeyToEvict;
-    bool m_isFull;
 };
 
 } // namespace JSC