Changeset 27216 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


Ignore:
Timestamp:
Oct 29, 2007, 12:05:49 AM (18 years ago)
Author:
oliver
Message:

Added nodes to allow Assignment, TypeOf, and prefix operators to
make use of the new optimised local variable look up.

5% gain on sunspider

Reviewed by Darin

File:
1 edited

Legend:

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

    r27215 r27216  
    11771177}
    11781178
     1179void TypeOfResolveNode::optimizeVariableAccess(FunctionBodyNode* functionBody, DeclarationStacks::NodeStack&)
     1180{
     1181    size_t index = functionBody->symbolTable().get(m_ident.ustring().rep());
     1182    if (index != missingSymbolMarker())
     1183        new (this) LocalTypeOfAccessNode(index);
     1184}
     1185
     1186JSValue* LocalTypeOfAccessNode::evaluate(ExecState* exec)
     1187{
     1188    ActivationImp* variableObject = static_cast<ActivationImp*>(exec->variableObject());
     1189    ASSERT(variableObject->isActivation());
     1190    ASSERT(variableObject == exec->scopeChain().top());
     1191    return typeStringForValue(variableObject->localStorage()[m_index].value);
     1192}
     1193
    11791194JSValue *TypeOfResolveNode::evaluate(ExecState *exec)
    11801195{
     
    12141229
    12151230// ------------------------------ PrefixResolveNode ----------------------------------
     1231
     1232void PrefixResolveNode::optimizeVariableAccess(FunctionBodyNode* functionBody, DeclarationStacks::NodeStack&)
     1233{
     1234    size_t index = functionBody->symbolTable().get(m_ident.ustring().rep());
     1235    if (index != missingSymbolMarker())
     1236        new (this) PrefixLocalAccessNode(index);
     1237}
     1238
     1239JSValue* PrefixLocalAccessNode::evaluate(ExecState* exec)
     1240{
     1241    ActivationImp* variableObject = static_cast<ActivationImp*>(exec->variableObject());
     1242    ASSERT(variableObject->isActivation());
     1243    ASSERT(variableObject == exec->scopeChain().top());
     1244    JSValue* v = variableObject->localStorage()[m_index].value;
     1245
     1246    double n = v->toNumber(exec);
     1247       
     1248    double newValue = (m_oper == OpPlusPlus) ? n + 1 : n - 1;
     1249    JSValue* n2 = jsNumber(newValue);
     1250    variableObject->localStorage()[m_index].value = n2;
     1251    return n2;
     1252}
    12161253
    12171254JSValue *PrefixResolveNode::evaluate(ExecState *exec)
     
    19642001// ------------------------------ AssignResolveNode -----------------------------------
    19652002
    1966 void AssignResolveNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
     2003void AssignResolveNode::optimizeVariableAccess(FunctionBodyNode* functionBody, DeclarationStacks::NodeStack& nodeStack)
    19672004{
    19682005    nodeStack.append(m_right.get());
     2006    size_t index = functionBody->symbolTable().get(m_ident.ustring().rep());
     2007    if (index != missingSymbolMarker())
     2008        new (this) AssignLocalAccessNode(index);
     2009}
     2010
     2011JSValue* AssignLocalAccessNode::evaluate(ExecState* exec)
     2012{
     2013    ActivationImp* variableObject = static_cast<ActivationImp*>(exec->variableObject());
     2014    ASSERT(variableObject->isActivation());
     2015    ASSERT(variableObject == exec->scopeChain().top());
     2016    JSValue* v;
     2017
     2018    if (m_oper == OpEqual)
     2019        v = m_right->evaluate(exec);
     2020    else {
     2021        JSValue* v1 = variableObject->localStorage()[m_index].value;
     2022        KJS_CHECKEXCEPTIONVALUE
     2023        JSValue* v2 = m_right->evaluate(exec);
     2024        v = valueForReadModifyAssignment(exec, v1, v2, m_oper);
     2025    }
     2026
     2027    KJS_CHECKEXCEPTIONVALUE
     2028
     2029    variableObject->localStorage()[m_index].value = v;
     2030    return v;
    19692031}
    19702032
Note: See TracChangeset for help on using the changeset viewer.