diff options
author | Andreas Kling <kling@serenityos.org> | 2021-03-21 17:38:42 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-21 21:39:39 +0100 |
commit | e0abfcb27d7293cd2da27ef85ae8e47d150bff4f (patch) | |
tree | 17b4022ca9af7ce17681d51cd7e5e4d30ea18176 /Userland/Libraries/LibJS/Interpreter.h | |
parent | 46e61d208bd19e5e0e406d94a69e4b582ee32dc5 (diff) | |
download | serenity-e0abfcb27d7293cd2da27ef85ae8e47d150bff4f.zip |
LibJS: Don't track executing AST nodes in a Vector
Instead just link together the InterpreterNodeScopes in a linked list.
This was surprisingly hot on CanvasCycle.
Diffstat (limited to 'Userland/Libraries/LibJS/Interpreter.h')
-rw-r--r-- | Userland/Libraries/LibJS/Interpreter.h | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Interpreter.h b/Userland/Libraries/LibJS/Interpreter.h index a2b801cefa..d9bea8e63a 100644 --- a/Userland/Libraries/LibJS/Interpreter.h +++ b/Userland/Libraries/LibJS/Interpreter.h @@ -44,6 +44,11 @@ namespace JS { +struct ExecutingASTNodeChain { + ExecutingASTNodeChain* previous { nullptr }; + const ASTNode& node; +}; + class Interpreter : public Weakable<Interpreter> { public: template<typename GlobalObjectType, typename... Args> @@ -77,14 +82,21 @@ public: void enter_scope(const ScopeNode&, ScopeType, GlobalObject&); void exit_scope(const ScopeNode&); - void enter_node(const ASTNode&); - void exit_node(const ASTNode&); + void push_ast_node(ExecutingASTNodeChain& chain_node) + { + chain_node.previous = m_ast_node_chain; + m_ast_node_chain = &chain_node; + } - void push_ast_node(const ASTNode& node) { m_ast_nodes.append(&node); } - void pop_ast_node() { m_ast_nodes.take_last(); } + void pop_ast_node() + { + VERIFY(m_ast_node_chain); + m_ast_node_chain = m_ast_node_chain->previous; + } - const ASTNode* current_node() const { return !m_ast_nodes.is_empty() ? m_ast_nodes.last() : nullptr; } - const Vector<const ASTNode*>& node_stack() const { return m_ast_nodes; } + const ASTNode* current_node() const { return m_ast_node_chain ? &m_ast_node_chain->node : nullptr; } + ExecutingASTNodeChain* executing_ast_node_chain() { return m_ast_node_chain; } + const ExecutingASTNodeChain* executing_ast_node_chain() const { return m_ast_node_chain; } Value execute_statement(GlobalObject&, const Statement&, ScopeType = ScopeType::Block); @@ -94,7 +106,7 @@ private: void push_scope(ScopeFrame frame); Vector<ScopeFrame> m_scope_stack; - Vector<const ASTNode*> m_ast_nodes; + ExecutingASTNodeChain* m_ast_node_chain { nullptr }; NonnullRefPtr<VM> m_vm; |