mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:07:35 +00:00
LibJS: Memoize failed calls of try_parse_arrow_function_expression()
This commit is contained in:
parent
435bd841ee
commit
8c80eb8870
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