Changeset 10168 in webkit for trunk/JavaScriptCore


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
Location:
trunk/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r10154 r10168  
     12005-08-12  Maciej Stachowiak  <[email protected]>
     2
     3        Reviewed by John.
     4
     5        - two simple speed improvements for a 3% speed gain
     6       
     7        * JavaScriptCore.xcodeproj/project.pbxproj: turn on -fstrict-aliasing
     8
     9        * kjs/scope_chain.h:
     10        (KJS::ScopeChainIterator::ScopeChainIterator): Add a scope chain iterator
     11        so you can walk a scope chain without having to make a copy that you then mutate.
     12        (KJS::ScopeChainIterator::operator*): standard iterator operation
     13        (KJS::ScopeChainIterator::operator->): ditto
     14        (KJS::ScopeChainIterator::operator++): ditto
     15        (KJS::ScopeChainIterator::operator==): ditto
     16        (KJS::ScopeChainIterator::operator!=): ditto
     17        (KJS::ScopeChain::begin): Iterator for the top of the scope chain
     18        (KJS::ScopeChain::end): Iterator for one past the bottom (i.e. null)
     19        * kjs/nodes.cpp:
     20        (ResolveNode::evaluate): Use scope chain iterator instead of copying
     21        a scope chain and then modifying the copy
     22        (ResolveNode::evaluateReference): ditto
     23        (FunctionCallResolveNode::evaluate): ditto
     24        (AssignResolveNode::evaluate): ditto
     25
    1262005-08-12  Maciej Stachowiak  <[email protected]>
    227
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r10084 r10168  
    17271727                                        HAVE_CONFIG_H,
    17281728                                );
     1729                                GCC_STRICT_ALIASING = YES;
    17291730                                GCC_TREAT_WARNINGS_AS_ERRORS = YES;
    17301731                                GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
     
    17341735                                INSTALL_PATH = /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks;
    17351736                                MACOSX_DEPLOYMENT_TARGET = 10.3;
     1737                                OTHER_CFLAGS = "";
    17361738                                OTHER_LDFLAGS = (
    17371739                                        "$(STYLE_LDFLAGS)",
     
    17781780                                        HAVE_CONFIG_H,
    17791781                                );
     1782                                GCC_STRICT_ALIASING = YES;
    17801783                                GCC_TREAT_WARNINGS_AS_ERRORS = YES;
    17811784                                GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
     
    17851788                                INSTALL_PATH = /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks;
    17861789                                MACOSX_DEPLOYMENT_TARGET = 10.3;
     1790                                OTHER_CFLAGS = "";
    17871791                                OTHER_LDFLAGS = (
    17881792                                        "$(STYLE_LDFLAGS)",
     
    18291833                                        HAVE_CONFIG_H,
    18301834                                );
     1835                                GCC_STRICT_ALIASING = YES;
    18311836                                GCC_TREAT_WARNINGS_AS_ERRORS = YES;
    18321837                                GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
     
    18361841                                INSTALL_PATH = /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks;
    18371842                                MACOSX_DEPLOYMENT_TARGET = 10.3;
     1843                                OTHER_CFLAGS = "";
    18381844                                OTHER_LDFLAGS = (
    18391845                                        "$(STYLE_LDFLAGS)",
     
    18801886                                        HAVE_CONFIG_H,
    18811887                                );
     1888                                GCC_STRICT_ALIASING = YES;
    18821889                                GCC_TREAT_WARNINGS_AS_ERRORS = YES;
    18831890                                GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
     
    18861893                                INFOPLIST_FILE = Info.plist;
    18871894                                INSTALL_PATH = /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks;
     1895                                OTHER_CFLAGS = "";
    18881896                                OTHER_LDFLAGS = (
    18891897                                        "$(STYLE_LDFLAGS)",
     
    22772285                        isa = XCBuildConfiguration;
    22782286                        buildSettings = {
     2287                                GCC_ENABLE_OBJC_GC = YES;
     2288                                GCC_FAST_OBJC_DISPATCH = YES;
     2289                                GCC_STRICT_ALIASING = YES;
    22792290                                GCC_THREADSAFE_STATICS = NO;
    22802291                        };
     
    22842295                        isa = XCBuildConfiguration;
    22852296                        buildSettings = {
     2297                                GCC_ENABLE_OBJC_GC = YES;
     2298                                GCC_FAST_OBJC_DISPATCH = YES;
     2299                                GCC_OPTIMIZATION_LEVEL = s;
     2300                                GCC_STRICT_ALIASING = YES;
    22862301                                GCC_THREADSAFE_STATICS = NO;
    22872302                        };
     
    22912306                        isa = XCBuildConfiguration;
    22922307                        buildSettings = {
     2308                                GCC_ENABLE_OBJC_GC = YES;
     2309                                GCC_FAST_OBJC_DISPATCH = YES;
     2310                                GCC_STRICT_ALIASING = YES;
    22932311                                GCC_THREADSAFE_STATICS = NO;
    22942312                        };
     
    22982316                        isa = XCBuildConfiguration;
    22992317                        buildSettings = {
     2318                                GCC_ENABLE_OBJC_GC = YES;
     2319                                GCC_FAST_OBJC_DISPATCH = YES;
     2320                                GCC_STRICT_ALIASING = YES;
    23002321                                GCC_THREADSAFE_STATICS = NO;
    23012322                        };
  • 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)
  • trunk/JavaScriptCore/kjs/scope_chain.h

    r9768 r10168  
    4141    };
    4242
     43    class ScopeChainIterator {
     44    public:
     45        ScopeChainIterator(ScopeChainNode *node) : m_node(node) {}
     46
     47        ObjectImp * const & operator*() const { return m_node->object; }
     48        ObjectImp * const * operator->() const { return &(operator*()); }
     49   
     50        ScopeChainIterator& operator++() { m_node = m_node->next; return *this; }
     51
     52        // postfix ++ intentionally omitted
     53
     54        bool operator==(const ScopeChainIterator& other) const { return m_node == other.m_node; }
     55        bool operator!=(const ScopeChainIterator& other) const { return m_node != other.m_node; }
     56
     57    private:
     58        ScopeChainNode *m_node;
     59    };
     60
    4361    class ScopeChain {
    4462    public:
     
    5472
    5573        ObjectImp *bottom() const;
     74
     75        ScopeChainIterator begin() const { return ScopeChainIterator(_node); }
     76        ScopeChainIterator end() const { return ScopeChainIterator(0); }
    5677
    5778        void clear() { deref(); _node = 0; }
Note: See TracChangeset for help on using the changeset viewer.