#include "RegExp.h"
#include "RegExpKey.h"
-#include "UString.h"
+#include "Strong.h"
+#include "Weak.h"
+#include "WeakInlines.h"
+#include <array>
+#include <wtf/HashMap.h>
#ifndef RegExpCache_h
#define RegExpCache_h
namespace JSC {
-class RegExpCache {
+class RegExpCache : private WeakHandleOwner {
+ WTF_MAKE_FAST_ALLOCATED;
+
+ 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; }
+ RegExpCache(VM* vm);
+ void invalidateCode();
private:
- static const unsigned maxCacheablePatternLength = 256;
- static const int maxCacheableEntries = 32;
-
- typedef HashMap<RegExpKey, RefPtr<RegExp> > RegExpCacheMap;
- RegExpKey patternKeyArray[maxCacheableEntries];
- RegExpCacheMap m_cacheMap;
- JSGlobalData* m_globalData;
- int m_nextKeyToEvict;
- bool m_isFull;
+
+ static const unsigned maxStrongCacheablePatternLength = 256;
+
+ static const int maxStrongCacheableEntries = 32;
+
+ virtual void finalize(Handle<Unknown>, void* context) override;
+
+ RegExp* lookupOrCreate(const WTF::String& patternString, RegExpFlags);
+ void addToStrongCache(RegExp*);
+ RegExpCacheMap m_weakCache; // Holds all regular expressions currently live.
+ int m_nextEntryInStrongCache;
+ std::array<Strong<RegExp>, maxStrongCacheableEntries> m_strongCache; // Holds a select few regular expressions that have compiled and executed
+ VM* m_vm;
};
} // namespace JSC