mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-01 15:18:06 +00:00
LibJS: Memoize failed calls of try_parse_arrow_function_expression()
This commit is contained in:
parent
435bd841ee
commit
8c80eb8870
Notes:
sideshowbarker
2024-07-18 20:29:30 +09:00
Author: https://github.com/sunverwerth
Commit: 8c80eb8870
Pull-request: https://github.com/SerenityOS/serenity/pull/6251
Issue: https://github.com/SerenityOS/serenity/issues/3349
2 changed files with 46 additions and 4 deletions
|
@ -147,6 +147,10 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
struct TokenMemoization {
|
||||
bool try_parse_arrow_function_expression_failed;
|
||||
};
|
||||
|
||||
private:
|
||||
friend class ScopePusher;
|
||||
|
||||
|
@ -172,6 +176,9 @@ private:
|
|||
void discard_saved_state();
|
||||
Position position() const;
|
||||
|
||||
bool try_parse_arrow_function_expression_failed_at_position(const Position&) const;
|
||||
void set_try_parse_arrow_function_expression_failed_at_position(const Position&, bool);
|
||||
|
||||
struct RulePosition {
|
||||
AK_MAKE_NONCOPYABLE(RulePosition);
|
||||
AK_MAKE_NONMOVABLE(RulePosition);
|
||||
|
@ -220,9 +227,23 @@ private:
|
|||
explicit ParserState(Lexer);
|
||||
};
|
||||
|
||||
class PositionKeyTraits {
|
||||
public:
|
||||
static int hash(const Position& position)
|
||||
{
|
||||
return int_hash(position.line) ^ int_hash(position.column);
|
||||
}
|
||||
|
||||
static bool equals(const Position& a, const Position& b)
|
||||
{
|
||||
return a.column == b.column && a.line == b.line;
|
||||
}
|
||||
};
|
||||
|
||||
Vector<Position> m_rule_starts;
|
||||
ParserState m_parser_state;
|
||||
FlyString m_filename;
|
||||
Vector<ParserState> m_saved_state;
|
||||
HashMap<Position, TokenMemoization, PositionKeyTraits> m_token_memoizations;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue