ladybird/Userland/Libraries/LibJS/Bytecode/RegexTable.cpp
Andreas Kling c0f985ffcf LibJS/Bytecode: Don't reparse regular expressions on instantiation
The RegExpLiteral AST node already has the parsed regex::Parser::Result
so let's plumb that over to the bytecode executable instead of reparsing
the regex every time NewRegExp is executed.

~12% speed-up on language/literals/regexp/S7.8.5_A2.1_T2.js in test262.
2023-07-13 13:30:49 +02:00

29 lines
575 B
C++

/*
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Bytecode/RegexTable.h>
namespace JS::Bytecode {
RegexTableIndex RegexTable::insert(ParsedRegex regex)
{
m_regexes.append(move(regex));
return m_regexes.size() - 1;
}
ParsedRegex const& RegexTable::get(RegexTableIndex index) const
{
return m_regexes[index.value()];
}
void RegexTable::dump() const
{
outln("Regex Table:");
for (size_t i = 0; i < m_regexes.size(); i++)
outln("{}: {}", i, m_regexes[i].pattern);
}
}