99
1010#include " common/mixin/not_copyable.h"
1111#include " runtime-common/core/allocator/script-allocator.h"
12+ #include " runtime-common/core/runtime-core.h"
1213#include " runtime-common/core/std/containers.h"
1314#include " runtime-light/stdlib/string/regex-include.h"
1415#include " runtime-light/utils/concepts.h"
1516
1617struct RegexInstanceState final : private vk::not_copyable {
1718private:
18- template <hashable Key, typename Value>
19- using unordered_map = kphp::stl::unordered_map<Key, Value, kphp::memory::script_allocator>;
19+ template <typename Value>
20+ using string_unordered_map =
21+ kphp::stl::unordered_map<string, Value, kphp::memory::script_allocator, decltype ([](const string& s) noexcept { return static_cast <size_t >(s.hash ()); })>;
2022
2123 static constexpr size_t MAX_SUBPATTERNS_COUNT = 512 ;
2224
@@ -34,12 +36,13 @@ struct RegexInstanceState final : private vk::not_copyable {
3436 const regex_pcre2_compile_context_t compile_context;
3537 const regex_pcre2_match_context_t match_context;
3638 regex_pcre2_match_data_t regex_pcre2_match_data;
37- unordered_map<std::string_view, compiled_regex_cache_entry> regex_pcre2_code_cache;
39+ string_unordered_map< compiled_regex_cache_entry> regex_pcre2_code_cache;
3840
3941 RegexInstanceState () noexcept ;
4042
4143 void add_compiled_code (std::string_view regex, uint32_t compile_options, regex_pcre2_code_t regex_code) noexcept {
42- regex_pcre2_code_cache.emplace (regex, compiled_regex_cache_entry{.compile_options = compile_options, .regex_code = regex_code});
44+ regex_pcre2_code_cache.emplace (string{regex.data (), static_cast <string::size_type>(regex.size ())},
45+ compiled_regex_cache_entry{.compile_options = compile_options, .regex_code = regex_code});
4346 }
4447
4548 static RegexInstanceState& get () noexcept ;
0 commit comments