From 2e06d26ddb0c13b8c90933e619876281ce8eeab2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 2 Sep 2024 11:42:48 +0200 Subject: [PATCH] LibJS: Remember arrow function parsing failures by offset We don't need to remember these by (line, column, offset). Just the offset should be enough. --- Userland/Libraries/LibJS/Parser.cpp | 4 ++-- Userland/Libraries/LibJS/Parser.h | 15 +-------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 45b6bab6c5..fb82be4089 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -4487,7 +4487,7 @@ Position Parser::position() const bool Parser::try_parse_arrow_function_expression_failed_at_position(Position const& position) const { - auto it = m_token_memoizations.find(position); + auto it = m_token_memoizations.find(position.offset); if (it == m_token_memoizations.end()) return false; @@ -4496,7 +4496,7 @@ bool Parser::try_parse_arrow_function_expression_failed_at_position(Position con void Parser::set_try_parse_arrow_function_expression_failed_at_position(Position const& position, bool failed) { - m_token_memoizations.set(position, { failed }); + m_token_memoizations.set(position.offset, { failed }); } void Parser::syntax_error(ByteString const& message, Optional position) diff --git a/Userland/Libraries/LibJS/Parser.h b/Userland/Libraries/LibJS/Parser.h index 523f14914f..6fb7df4426 100644 --- a/Userland/Libraries/LibJS/Parser.h +++ b/Userland/Libraries/LibJS/Parser.h @@ -334,19 +334,6 @@ private: ParserState(Lexer, Program::Type); }; - class PositionKeyTraits { - public: - static int hash(Position const& position) - { - return int_hash(position.line) ^ int_hash(position.column); - } - - static bool equals(Position const& a, Position const& b) - { - return a.column == b.column && a.line == b.line; - } - }; - [[nodiscard]] NonnullRefPtr create_identifier_and_register_in_current_scope(SourceRange range, DeprecatedFlyString string, Optional = {}); NonnullRefPtr m_source_code; @@ -354,7 +341,7 @@ private: ParserState m_state; DeprecatedFlyString m_filename; Vector m_saved_state; - HashMap m_token_memoizations; + HashMap m_token_memoizations; Program::Type m_program_type; }; }