Ignore:
Timestamp:
Dec 24, 2007, 2:13:00 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Eric.


3.5% speedup on SunSpider.

var statements now result in either assignments or empty statements.


This allows a couple of optimization opportunities:

  • No need to branch at runtime to check if there is an initializer
  • EmptyStatementNodes can be removed entirely (also done in this patch)
  • Assignment expressions get properly optimized for local variables


This patch also includes some code cleanup:

  • Most of the old VarStatement/VarDecl logic is now only used for const declarations, thus it is renamed appropriately
  • AssignExprNode is gone


  • JavaScriptCore.exp:
  • kjs/NodeInfo.h:
  • kjs/grammar.y:
  • kjs/nodes.cpp: (KJS::SourceElements::append): (KJS::ConstDeclNode::ConstDeclNode): (KJS::ConstDeclNode::optimizeVariableAccess): (KJS::ConstDeclNode::handleSlowCase): (KJS::ConstDeclNode::evaluateSingle): (KJS::ConstDeclNode::evaluate): (KJS::ConstStatementNode::optimizeVariableAccess): (KJS::ConstStatementNode::execute): (KJS::VarStatementNode::optimizeVariableAccess): (KJS::VarStatementNode::execute): (KJS::ForInNode::ForInNode): (KJS::ForInNode::optimizeVariableAccess): (KJS::ForInNode::execute): (KJS::FunctionBodyNode::initializeSymbolTable): (KJS::ProgramNode::initializeSymbolTable): (KJS::FunctionBodyNode::processDeclarations): (KJS::ProgramNode::processDeclarations): (KJS::EvalNode::processDeclarations):
  • kjs/nodes.h: (KJS::DeclarationStacks::): (KJS::StatementNode::): (KJS::ConstDeclNode::): (KJS::ConstStatementNode::): (KJS::EmptyStatementNode::): (KJS::VarStatementNode::): (KJS::ForNode::):
  • kjs/nodes2string.cpp: (KJS::ConstDeclNode::streamTo): (KJS::ConstStatementNode::streamTo): (KJS::ScopeNode::streamTo): (KJS::VarStatementNode::streamTo): (KJS::ForNode::streamTo): (KJS::ForInNode::streamTo):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes2string.cpp

    r28937 r28973  
    708708}
    709709
    710 void AssignExprNode::streamTo(SourceStream& s) const
    711 {
    712     s << " = " << PrecAssignment << expr;
    713 }
    714 
    715 void VarDeclNode::streamTo(SourceStream& s) const
    716 {
    717     s << "var " << ident << init;
    718     for (VarDeclNode* n = next.get(); n; n = n->next.get())
    719         s << ", " << ident << init;
    720 }
    721 
    722 void VarStatementNode::streamTo(SourceStream& s) const
    723 {
    724     s << Endl << next << ';';
     710void ConstDeclNode::streamTo(SourceStream& s) const
     711{
     712    s << ident;
     713    if (init)
     714        s << " = " << init;
     715    for (ConstDeclNode* n = next.get(); n; n = n->next.get()) {
     716        s << ", " << ident;
     717        if (init)
     718            s << " = " << init;
     719    }
     720}
     721
     722void ConstStatementNode::streamTo(SourceStream& s) const
     723{
     724    s << Endl << "const " << next << ';';
    725725}
    726726
     
    738738}
    739739
     740void ScopeNode::streamTo(SourceStream& s) const
     741{
     742    s << Endl << "{" << Indent;
     743
     744    bool printedVar = false;
     745    for (size_t i = 0; i < m_varStack.size(); ++i) {
     746        if (m_varStack[i].second == 0) {
     747            if (!printedVar) {
     748                s << Endl << "var ";
     749                printedVar = true;
     750            } else
     751                s << ", ";
     752            s << m_varStack[i].first;
     753        }
     754    }
     755    if (printedVar)
     756        s << ';';
     757
     758    statementListStreamTo(m_children, s);
     759    s << Unindent << Endl << "}";
     760}
     761
    740762void EmptyStatementNode::streamTo(SourceStream& s) const
    741763{
     
    746768{
    747769    s << Endl << expr << ';';
     770}
     771
     772void VarStatementNode::streamTo(SourceStream& s) const
     773{
     774    s << Endl << "var " << expr << ';';
    748775}
    749776
     
    773800{
    774801    s << Endl << "for ("
     802        << (expr1WasVarDecl ? "var " : "")
    775803        << expr1
    776804        << "; " << expr2
     
    782810{
    783811    s << Endl << "for (";
    784     if (varDecl)
    785         s << varDecl;
    786     else
     812    if (identIsVarDecl) {
     813        s << "var ";
     814        if (init)
     815            s << init;
     816        else
     817            s << PrecLeftHandSide << lexpr;
     818    } else
    787819        s << PrecLeftHandSide << lexpr;
    788820
Note: See TracChangeset for help on using the changeset viewer.