From 37d722f4a6ad0f4d5cf3dc20b4deced1a0cba671 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 6 May 2024 10:12:02 +0200 Subject: [PATCH] LibJS/Bytecode: Make IdentifierTableIndex a 32-bit index This makes a bunch of instructions smaller. --- Userland/Libraries/LibJS/Bytecode/IdentifierTable.cpp | 5 +++-- Userland/Libraries/LibJS/Bytecode/IdentifierTable.h | 5 ++++- Userland/Libraries/LibJS/Bytecode/Interpreter.cpp | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/IdentifierTable.cpp b/Userland/Libraries/LibJS/Bytecode/IdentifierTable.cpp index 7347a90c879..121bbacab2a 100644 --- a/Userland/Libraries/LibJS/Bytecode/IdentifierTable.cpp +++ b/Userland/Libraries/LibJS/Bytecode/IdentifierTable.cpp @@ -11,12 +11,13 @@ namespace JS::Bytecode { IdentifierTableIndex IdentifierTable::insert(DeprecatedFlyString string) { m_identifiers.append(move(string)); - return m_identifiers.size() - 1; + VERIFY(m_identifiers.size() <= NumericLimits::max()); + return { static_cast(m_identifiers.size() - 1) }; } DeprecatedFlyString const& IdentifierTable::get(IdentifierTableIndex index) const { - return m_identifiers[index.value()]; + return m_identifiers[index.value]; } void IdentifierTable::dump() const diff --git a/Userland/Libraries/LibJS/Bytecode/IdentifierTable.h b/Userland/Libraries/LibJS/Bytecode/IdentifierTable.h index b22a8538798..1e02723b2b0 100644 --- a/Userland/Libraries/LibJS/Bytecode/IdentifierTable.h +++ b/Userland/Libraries/LibJS/Bytecode/IdentifierTable.h @@ -12,7 +12,10 @@ namespace JS::Bytecode { -AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(size_t, IdentifierTableIndex, Comparison); +struct IdentifierTableIndex { + bool is_valid() const { return value != NumericLimits::max(); } + u32 value { 0 }; +}; class IdentifierTable { AK_MAKE_NONMOVABLE(IdentifierTable); diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 2b55780bad2..350b4f00350 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1758,7 +1758,7 @@ ByteString GetGlobal::to_byte_string_impl(Bytecode::Executable const& executable ByteString DeleteVariable::to_byte_string_impl(Bytecode::Executable const& executable) const { - return ByteString::formatted("DeleteVariable {} ({})", m_identifier, executable.identifier_table->get(m_identifier)); + return ByteString::formatted("DeleteVariable {}", executable.identifier_table->get(m_identifier)); } ByteString CreateLexicalEnvironment::to_byte_string_impl(Bytecode::Executable const&) const @@ -1769,7 +1769,7 @@ ByteString CreateLexicalEnvironment::to_byte_string_impl(Bytecode::Executable co ByteString CreateVariable::to_byte_string_impl(Bytecode::Executable const& executable) const { auto mode_string = m_mode == EnvironmentMode::Lexical ? "Lexical" : "Variable"; - return ByteString::formatted("CreateVariable env:{} immutable:{} global:{} {} ({})", mode_string, m_is_immutable, m_is_global, m_identifier, executable.identifier_table->get(m_identifier)); + return ByteString::formatted("CreateVariable env:{} immutable:{} global:{} {}", mode_string, m_is_immutable, m_is_global, executable.identifier_table->get(m_identifier)); } ByteString EnterObjectEnvironment::to_byte_string_impl(Executable const& executable) const @@ -2010,7 +2010,7 @@ ByteString NewClass::to_byte_string_impl(Bytecode::Executable const& executable) if (!name.is_empty()) builder.appendff(", {}", name); if (m_lhs_name.has_value()) - builder.appendff(", lhs_name:{}"sv, m_lhs_name.value()); + builder.appendff(", lhs_name:{}"sv, executable.get_identifier(m_lhs_name.value())); return builder.to_byte_string(); }