Ignore:
Timestamp:
Dec 8, 2014, 5:53:53 PM (10 years ago)
Author:
[email protected]
Message:

Source/JavaScriptCore:
Removed some allocation and cruft from the parser
https://bugs.webkit.org/show_bug.cgi?id=139416

Reviewed by Mark Lam.

Now, the only AST nodes that require a destructor are the ones that
relate to pickling a function's arguments -- which will required some
deeper thinking to resolve.

This is a < 1% parser speedup.

was unused.

  • bytecompiler/NodesCodegen.cpp:

(JSC::CommaNode::emitBytecode):
(JSC::SourceElements::lastStatement):
(JSC::SourceElements::emitBytecode): Updated for interface change to linked list.

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::ASTBuilder):
(JSC::ASTBuilder::varDeclarations):
(JSC::ASTBuilder::funcDeclarations):
(JSC::ASTBuilder::createFuncDeclStatement):
(JSC::ASTBuilder::addVar): Removed the ParserArenaData abstraction because
it wasn't buying us anything. We can just use Vector directly.

(JSC::ASTBuilder::createCommaExpr):
(JSC::ASTBuilder::appendToCommaExpr): Changed to use a linked list instead
of a vector, to avoid allocating a vector with inline capacity in the
common case in which an expression is not followed by a vector.

(JSC::ASTBuilder::Scope::Scope): Use Vector directly to avoid new'ing
up a Vector*.

(JSC::ASTBuilder::appendToComma): Deleted.
(JSC::ASTBuilder::combineCommaNodes): Deleted.

  • parser/Lexer.cpp:
  • parser/NodeConstructors.h:

(JSC::StatementNode::StatementNode):
(JSC::CommaNode::CommaNode):
(JSC::SourceElements::SourceElements): Updated for interface change to linked list.

  • parser/NodeInfo.h: Removed.
  • parser/Nodes.cpp:

(JSC::SourceElements::append):
(JSC::SourceElements::singleStatement): Use a linked list instead of a
vector to track the statements in a list. This removes some allocation
and it means that we don't need a destructor anymore.

(JSC::ScopeNode::ScopeNode):
(JSC::ProgramNode::ProgramNode):
(JSC::EvalNode::EvalNode):
(JSC::FunctionNode::FunctionNode): Updated for interface change to reference,
since these values are never null.

  • parser/Nodes.h:

(JSC::StatementNode::next):
(JSC::StatementNode::setNext):
(JSC::CommaNode::append): Deleted. Updated for interface change to linked list.

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::didFinishParsing): Updated for interface change to reference.

(JSC::Parser<LexerType>::parseVarDeclarationList):
(JSC::Parser<LexerType>::parseExpression): Track comma expressions as
an explicit list of CommaNodes, removing a use of vector and a destructor.

  • parser/Parser.h:

(JSC::Parser<LexerType>::parse):

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::createCommaExpr):
(JSC::SyntaxChecker::appendToCommaExpr):
(JSC::SyntaxChecker::appendToComma): Deleted. Updated for interface changes.

LayoutTests:
Removed the custom allocator for ParserArena
https://bugs.webkit.org/show_bug.cgi?id=139305

Reviewed by Mark Lam.

Added a test for something I messed up while writing this patch.

  • js/basic-strict-mode-expected.txt:
  • js/script-tests/basic-strict-mode.js:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Nodes.h

    r176836 r177001  
    107107    };
    108108
    109     template <typename T>
    110     struct ParserArenaData : ParserArenaDeletable {
    111         T data;
    112     };
    113 
    114109    class ParserArenaRoot {
    115110        WTF_MAKE_FAST_ALLOCATED;
     
    191186        unsigned lastLine() const { return m_lastLine; }
    192187
     188        StatementNode* next() { return m_next; }
     189        void setNext(StatementNode* next) { m_next = next; }
     190
    193191        virtual bool isEmptyStatement() const { return false; }
    194192        virtual bool isReturnNode() const { return false; }
     
    199197
    200198    protected:
     199        StatementNode* m_next;
    201200        int m_lastLine;
    202201    };
     
    10981097    };
    10991098   
    1100     typedef Vector<ExpressionNode*, 8> ExpressionVector;
    1101 
    1102     class CommaNode : public ExpressionNode, public ParserArenaDeletable {
    1103     public:
    1104         CommaNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2);
    1105 
    1106         using ParserArenaDeletable::operator new;
    1107 
    1108         void append(ExpressionNode* expr) { ASSERT(expr); m_expressions.append(expr); }
     1099    class CommaNode final : public ExpressionNode, public ParserArenaFreeable {
     1100    public:
     1101        CommaNode(const JSTokenLocation&, ExpressionNode*);
     1102
     1103        void setNext(CommaNode* next) { m_next = next; }
     1104        CommaNode* next() { return m_next; }
    11091105
    11101106    private:
     
    11121108        virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override;
    11131109
    1114         ExpressionVector m_expressions;
     1110        ExpressionNode* m_expr;
     1111        CommaNode* m_next;
    11151112    };
    11161113   
     
    11451142    };
    11461143
    1147     class SourceElements : public ParserArenaDeletable {
     1144    class SourceElements final : public ParserArenaFreeable {
    11481145    public:
    11491146        SourceElements();
     
    11571154
    11581155    private:
    1159         Vector<StatementNode*> m_statements;
     1156        StatementNode* m_head;
     1157        StatementNode* m_tail;
    11601158    };
    11611159
     
    14121410
    14131411        ScopeNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, bool inStrictContext);
    1414         ScopeNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, CodeFeatures, int numConstants);
     1412        ScopeNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, const SourceCode&, SourceElements*, VarStack&, FunctionStack&, IdentifierSet&, CodeFeatures, int numConstants);
    14151413
    14161414        using ParserArenaRoot::operator new;
     
    14741472    class ProgramNode : public ScopeNode {
    14751473    public:
    1476         ProgramNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, unsigned endColumn, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
     1474        ProgramNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, unsigned endColumn, SourceElements*, VarStack&, FunctionStack&, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
    14771475
    14781476        unsigned startColumn() const { return m_startColumn; }
     
    14931491    class EvalNode : public ScopeNode {
    14941492    public:
    1495         EvalNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, unsigned endColumn, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
     1493        EvalNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, unsigned endColumn, SourceElements*, VarStack&, FunctionStack&, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
    14961494
    14971495        ALWAYS_INLINE unsigned startColumn() const { return 0; }
     
    15741572    class FunctionNode final : public ScopeNode {
    15751573    public:
    1576         FunctionNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, unsigned endColumn, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
     1574        FunctionNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, unsigned endColumn, SourceElements*, VarStack&, FunctionStack&, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
    15771575
    15781576        FunctionParameters* parameters() const { return m_parameters.get(); }
Note: See TracChangeset for help on using the changeset viewer.