diff --git a/ecmascript/builtins/builtins_regexp.cpp b/ecmascript/builtins/builtins_regexp.cpp index a7e470d02350acec5e7ea0a8f0231a5d4d2d294a..254e994195d3824d81916ffc762afbef2dc374d2 100644 --- a/ecmascript/builtins/builtins_regexp.cpp +++ b/ecmascript/builtins/builtins_regexp.cpp @@ -2583,6 +2583,34 @@ JSTaggedValue RegExpExecResultCache::CreateCacheTable(JSThread *thread) return JSTaggedValue(table); } +void RegExpExecResultCache::ClearCache(JSThread* thread, JSHandle cache) +{ + if (cache->IsUndefined()) { + return; + } + JSHandle regexpCache(cache); + if (regexpCache->GetCacheCount() == 0) { + return; + } + if (regexpCache->GetNeedUpdateGlobal()) { + JSHandle env = thread->GetGlobalEnv(); + ASSERT(!env.GetTaggedValue().IsHole()); + const int lastMatchIndex = regexpCache->GetLastMatchGlobalTableIndex(); + ASSERT(lastMatchIndex != -1); + env->SetRegExpGlobalResult(thread, regexpCache->Get(thread, lastMatchIndex + CAPTURE_SIZE)); + } + regexpCache->SetLargeStrCount(thread, DEFAULT_LARGE_STRING_COUNT); + regexpCache->SetConflictCount(thread, DEFAULT_CONFLICT_COUNT); + regexpCache->SetStrLenThreshold(thread, 0); + regexpCache->SetHitCount(thread, 0); + regexpCache->SetCacheCount(thread, 0); + regexpCache->SetLastMatchGlobalTableIndex(thread, DEFAULT_LAST_MATCH_INDEX); + regexpCache->SetUseLastMatch(thread, false); + regexpCache->SetNeedUpdateGlobal(thread, false); + std::fill_n(regexpCache->GetData() + CACHE_TABLE_HEADER_SIZE, regexpCache->GetLength() - CACHE_TABLE_HEADER_SIZE, + JSTaggedValue::Undefined().GetRawData()); +} + void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandle cache, const JSHandle regexp, const JSHandle input, diff --git a/ecmascript/builtins/builtins_regexp.h b/ecmascript/builtins/builtins_regexp.h index 285fde67fd54fe14629b28fc37e2c3d51fe373e8..8040df21ca9a2d06d2c72da590641a00858c7d9d 100644 --- a/ecmascript/builtins/builtins_regexp.h +++ b/ecmascript/builtins/builtins_regexp.h @@ -225,6 +225,7 @@ public: return reinterpret_cast(object); } static JSTaggedValue CreateCacheTable(JSThread *thread); + static void ClearCache(JSThread* thread, JSHandle cache); // extend as an additional parameter to judge cached template JSTaggedValue FindCachedResult(JSThread *thread, const JSHandle input, @@ -350,7 +351,7 @@ private: static constexpr int DEFAULT_LARGE_STRING_COUNT = 10; static constexpr int DEFAULT_CONFLICT_COUNT = 100; static constexpr int INITIAL_CACHE_NUMBER = 0x10; - static constexpr int DEFAULT_CACHE_NUMBER = 0x1000; + static constexpr int DEFAULT_CACHE_NUMBER = 0x100; static constexpr int DEFAULT_LAST_MATCH_INDEX = -1; static constexpr int CACHE_COUNT_INDEX = 0; static constexpr int CACHE_HIT_COUNT_INDEX = 1; diff --git a/ecmascript/global_env.cpp b/ecmascript/global_env.cpp index 156b232c20c9e6e05301309bcc9642b3927b5b2b..a3b5efa7f51670606cebb5533b3c3e0f41b54dab 100644 --- a/ecmascript/global_env.cpp +++ b/ecmascript/global_env.cpp @@ -118,6 +118,7 @@ void GlobalEnv::NotifyArrayPrototypeChangedGuardians(JSThread *thread, JSHandle< void GlobalEnv::ClearCache(JSThread *thread) const { builtins::StringSplitResultCache::ClearCache(thread, GetStringSplitResultCache()); + builtins::RegExpExecResultCache::ClearCache(thread, GetRegExpCache()); } GlobalEnvField GetBuildinTypedArrayHClassOnHeapIndex(JSType jSType)