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.cpp

    r176825 r177001  
    6666    if (statement->isEmptyStatement())
    6767        return;
    68     m_statements.append(statement);
     68
     69    if (!m_head) {
     70        m_head = statement;
     71        m_tail = statement;
     72        return;
     73    }
     74
     75    m_tail->setNext(statement);
     76    m_tail = statement;
    6977}
    7078
    7179StatementNode* SourceElements::singleStatement() const
    7280{
    73     size_t size = m_statements.size();
    74     return size == 1 ? m_statements[0] : 0;
     81    return m_head == m_tail ? m_head : nullptr;
    7582}
    7683
     
    8996}
    9097
    91 ScopeNode::ScopeNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, const SourceCode& source, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, CodeFeatures features, int numConstants)
     98ScopeNode::ScopeNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, const SourceCode& source, SourceElements* children, VarStack& varStack, FunctionStack& funcStack, IdentifierSet& capturedVariables, CodeFeatures features, int numConstants)
    9299    : StatementNode(endLocation)
    93100    , ParserArenaRoot(parserArena)
     
    100107    , m_statements(children)
    101108{
    102     if (varStack)
    103         m_varStack.swap(*varStack);
    104     if (funcStack)
    105         m_functionStack.swap(*funcStack);
     109    m_varStack.swap(varStack);
     110    m_functionStack.swap(funcStack);
    106111    m_capturedVariables.swap(capturedVariables);
    107112}
     
    114119// ------------------------------ ProgramNode -----------------------------
    115120
    116 ProgramNode::ProgramNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants)
     121ProgramNode::ProgramNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, SourceElements* children, VarStack& varStack, FunctionStack& funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants)
    117122    : ScopeNode(parserArena, startLocation, endLocation, source, children, varStack, funcStack, capturedVariables, features, numConstants)
    118123    , m_startColumn(startColumn)
     
    128133// ------------------------------ EvalNode -----------------------------
    129134
    130 EvalNode::EvalNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned, unsigned endColumn, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants)
     135EvalNode::EvalNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned, unsigned endColumn, SourceElements* children, VarStack& varStack, FunctionStack& funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants)
    131136    : ScopeNode(parserArena, startLocation, endLocation, source, children, varStack, funcStack, capturedVariables, features, numConstants)
    132137    , m_endColumn(endColumn)
     
    189194// ------------------------------ FunctionNode -----------------------------
    190195
    191 FunctionNode::FunctionNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& sourceCode, CodeFeatures features, int numConstants)
     196FunctionNode::FunctionNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, SourceElements* children, VarStack& varStack, FunctionStack& funcStack, IdentifierSet& capturedVariables, const SourceCode& sourceCode, CodeFeatures features, int numConstants)
    192197    : ScopeNode(parserArena, startLocation, endLocation, sourceCode, children, varStack, funcStack, capturedVariables, features, numConstants)
    193198    , m_startColumn(startColumn)
Note: See TracChangeset for help on using the changeset viewer.