#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);
+ void invalidateCode();
private:
- static const unsigned maxCacheablePatternLength = 256;
- static const int maxCacheableEntries = 256;
+
+ 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