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


Ignore:
Timestamp:
Aug 12, 2005, 4:20:48 PM (20 years ago)
Author:
mjs
Message:

Reviewed by John.

  • two simple speed improvements for a 3% speed gain
  • kjs/scope_chain.h: (KJS::ScopeChainIterator::ScopeChainIterator): Add a scope chain iterator so you can walk a scope chain without having to make a copy that you then mutate. (KJS::ScopeChainIterator::operator*): standard iterator operation (KJS::ScopeChainIterator::operator->): ditto (KJS::ScopeChainIterator::operator++): ditto (KJS::ScopeChainIterator::operator==): ditto (KJS::ScopeChainIterator::operator!=): ditto (KJS::ScopeChain::begin): Iterator for the top of the scope chain (KJS::ScopeChain::end): Iterator for one past the bottom (i.e. null)
  • kjs/nodes.cpp: (ResolveNode::evaluate): Use scope chain iterator instead of copying a scope chain and then modifying the copy (ResolveNode::evaluateReference): ditto (FunctionCallResolveNode::evaluate): ditto (AssignResolveNode::evaluate): ditto
File:
1 edited

Legend:

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

    r10148 r10168  
    334334ValueImp *ResolveNode::evaluate(ExecState *exec)
    335335{
    336   ScopeChain chain = exec->context().imp()->scopeChain();
    337 
    338   assert(!chain.isEmpty());
     336  const ScopeChain& chain = exec->context().imp()->scopeChain();
     337  ScopeChainIterator iter = chain.begin();
     338  ScopeChainIterator end = chain.end();
     339 
     340  // we must always have something in the scope chain
     341  assert(iter != end);
    339342
    340343  PropertySlot slot;
    341344  do {
    342     ObjectImp *o = chain.top();
     345    ObjectImp *o = *iter;
    343346
    344347    if (o->getPropertySlot(exec, ident, slot))
    345348      return slot.getValue(exec, ident);
    346349   
    347     chain.pop();
    348   } while (!chain.isEmpty());
     350    ++iter;
     351  } while (iter != end);
    349352
    350353  return undefinedVariableError(exec, ident);
     
    353356Reference ResolveNode::evaluateReference(ExecState *exec)
    354357{
    355   ScopeChain chain = exec->context().imp()->scopeChain();
    356 
    357   assert(!chain.isEmpty());
     358  const ScopeChain& chain = exec->context().imp()->scopeChain();
     359  ScopeChainIterator iter = chain.begin();
     360  ScopeChainIterator end = chain.end();
     361 
     362  // we must always have something in the scope chain
     363  assert(iter != end);
    358364
    359365  PropertySlot slot;
    360366  do {
    361     ObjectImp *o = chain.top();
     367    ObjectImp *o = *iter;
    362368    if (o->getPropertySlot(exec, ident, slot))
    363369      return Reference(o, ident);
    364370   
    365     chain.pop();
    366   } while (!chain.isEmpty());
     371    ++iter;
     372  } while (iter != end);
    367373
    368374  return Reference(ident);
     
    818824ValueImp *FunctionCallResolveNode::evaluate(ExecState *exec)
    819825{
    820   ScopeChain chain = exec->context().imp()->scopeChain();
    821 
    822   assert(!chain.isEmpty());
     826  const ScopeChain& chain = exec->context().imp()->scopeChain();
     827  ScopeChainIterator iter = chain.begin();
     828  ScopeChainIterator end = chain.end();
     829 
     830  // we must always have something in the scope chain
     831  assert(iter != end);
    823832
    824833  PropertySlot slot;
    825834  ObjectImp *base;
    826835  do {
    827     base = chain.top();
     836    base = *iter;
    828837    if (base->getPropertySlot(exec, ident, slot)) {
    829838      ValueImp *v = slot.getValue(exec, ident);
     
    855864      return func->call(exec, thisObj, argList);
    856865    }
    857     chain.pop();
    858   } while (!chain.isEmpty());
     866    ++iter;
     867  } while (iter != end);
    859868 
    860869  return undefinedVariableError(exec, ident);
     
    16801689ValueImp *AssignResolveNode::evaluate(ExecState *exec)
    16811690{
    1682   ScopeChain chain = exec->context().imp()->scopeChain();
    1683 
    1684   assert(!chain.isEmpty());
     1691  const ScopeChain& chain = exec->context().imp()->scopeChain();
     1692  ScopeChainIterator iter = chain.begin();
     1693  ScopeChainIterator end = chain.end();
     1694 
     1695  // we must always have something in the scope chain
     1696  assert(iter != end);
    16851697
    16861698  PropertySlot slot;
    16871699  ObjectImp *base;
    16881700  do {
    1689     base = chain.top();
     1701    base = *iter;
    16901702    if (base->getPropertySlot(exec, m_ident, slot))
    16911703      goto found;
    16921704
    1693     chain.pop();
    1694   } while (!chain.isEmpty());
     1705    ++iter;
     1706  } while (iter != end);
    16951707
    16961708  if (m_oper != OpEqual)
Note: See TracChangeset for help on using the changeset viewer.