diff --git a/Libraries/LibJS/Bytecode/Generator.cpp b/Libraries/LibJS/Bytecode/Generator.cpp index dd07edb60eb..5fb900aa101 100644 --- a/Libraries/LibJS/Bytecode/Generator.cpp +++ b/Libraries/LibJS/Bytecode/Generator.cpp @@ -1344,6 +1344,12 @@ ScopedOperand Generator::add_constant(Value value) return append_new_constant(); }); } + if (value.is_string()) { + auto as_string = value.as_string().utf8_string(); + return m_string_constants.ensure(as_string, [&] { + return append_new_constant(); + }); + } return append_new_constant(); } diff --git a/Libraries/LibJS/Bytecode/Generator.h b/Libraries/LibJS/Bytecode/Generator.h index 980375a589d..e0cb070ac7d 100644 --- a/Libraries/LibJS/Bytecode/Generator.h +++ b/Libraries/LibJS/Bytecode/Generator.h @@ -397,6 +397,7 @@ private: mutable Optional m_undefined_constant; mutable Optional m_empty_constant; mutable HashMap m_int32_constants; + mutable HashMap m_string_constants; ScopedOperand m_accumulator; ScopedOperand m_this_value;