diff options
Diffstat (limited to 'JavaScriptCore/runtime/RegExpCache.cpp')
-rw-r--r-- | JavaScriptCore/runtime/RegExpCache.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/JavaScriptCore/runtime/RegExpCache.cpp b/JavaScriptCore/runtime/RegExpCache.cpp index 192df4d..b9d250d 100644 --- a/JavaScriptCore/runtime/RegExpCache.cpp +++ b/JavaScriptCore/runtime/RegExpCache.cpp @@ -34,25 +34,26 @@ namespace JSC { PassRefPtr<RegExp> RegExpCache::lookupOrCreate(const UString& patternString, const UString& flags) { if (patternString.size() < maxCacheablePatternLength) { - pair<HashMap<RegExpKey, RefPtr<RegExp> >::iterator, bool> result = m_cacheMap.add(RegExpKey(flags, patternString), 0); + pair<RegExpCacheMap::iterator, bool> result = m_cacheMap.add(RegExpKey(flags, patternString), 0); if (!result.second) return result.first->second; + else + return create(patternString, flags, result.first); } - return create(patternString, flags); + return create(patternString, flags, m_cacheMap.end()); } -PassRefPtr<RegExp> RegExpCache::create(const UString& patternString, const UString& flags) +PassRefPtr<RegExp> RegExpCache::create(const UString& patternString, const UString& flags, RegExpCacheMap::iterator iterator) { - RefPtr<RegExp> regExp; - - if (!flags.isNull()) - regExp = RegExp::create(m_globalData, patternString, flags); - else - regExp = RegExp::create(m_globalData, patternString); + RefPtr<RegExp> regExp = RegExp::create(m_globalData, patternString, flags); if (patternString.size() >= maxCacheablePatternLength) return regExp; + RegExpKey key = RegExpKey(flags, patternString); + iterator->first = key; + iterator->second = regExp; + ++m_nextKeyToEvict; if (m_nextKeyToEvict == maxCacheableEntries) { m_nextKeyToEvict = 0; @@ -61,8 +62,6 @@ PassRefPtr<RegExp> RegExpCache::create(const UString& patternString, const UStri if (m_isFull) m_cacheMap.remove(RegExpKey(patternKeyArray[m_nextKeyToEvict].flagsValue, patternKeyArray[m_nextKeyToEvict].pattern)); - RegExpKey key = RegExpKey(flags, patternString); - m_cacheMap.set(key, regExp); patternKeyArray[m_nextKeyToEvict].flagsValue = key.flagsValue; patternKeyArray[m_nextKeyToEvict].pattern = patternString.rep(); return regExp; |