[webkit-changes] cvs commit: JavaScriptCore/kjs nodes.cpp scope_chain.h

Maciej mjs at opensource.apple.com
Fri Aug 12 16:20:49 PDT 2005


mjs         05/08/12 16:20:48

  Modified:    .        ChangeLog
               JavaScriptCore.xcodeproj project.pbxproj
               kjs      nodes.cpp scope_chain.h
  Log:
          Reviewed by John.
  
  	- two simple speed improvements for a 3% speed gain
  
          * JavaScriptCore.xcodeproj/project.pbxproj: turn on -fstrict-aliasing
  
          * 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
  
  Revision  Changes    Path
  1.791     +25 -0     JavaScriptCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
  retrieving revision 1.790
  retrieving revision 1.791
  diff -u -r1.790 -r1.791
  --- ChangeLog	12 Aug 2005 19:58:16 -0000	1.790
  +++ ChangeLog	12 Aug 2005 23:20:47 -0000	1.791
  @@ -1,5 +1,30 @@
   2005-08-12  Maciej Stachowiak  <mjs at apple.com>
   
  +        Reviewed by John.
  +
  +	- two simple speed improvements for a 3% speed gain
  +	
  +        * JavaScriptCore.xcodeproj/project.pbxproj: turn on -fstrict-aliasing
  +
  +        * 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
  +
  +2005-08-12  Maciej Stachowiak  <mjs at apple.com>
  +
           Patch from Anders Carlsson, reviewed by me.
   
           * kjs/nodes.h: Fix build breakage.
  
  
  
  1.6       +21 -0     JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
  
  Index: project.pbxproj
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- project.pbxproj	8 Aug 2005 04:07:21 -0000	1.5
  +++ project.pbxproj	12 Aug 2005 23:20:47 -0000	1.6
  @@ -1726,6 +1726,7 @@
   					APPLE_CHANGES,
   					HAVE_CONFIG_H,
   				);
  +				GCC_STRICT_ALIASING = YES;
   				GCC_TREAT_WARNINGS_AS_ERRORS = YES;
   				GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
   				GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
  @@ -1733,6 +1734,7 @@
   				INFOPLIST_FILE = Info.plist;
   				INSTALL_PATH = /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks;
   				MACOSX_DEPLOYMENT_TARGET = 10.3;
  +				OTHER_CFLAGS = "";
   				OTHER_LDFLAGS = (
   					"$(STYLE_LDFLAGS)",
   					"-sub_library",
  @@ -1777,6 +1779,7 @@
   					APPLE_CHANGES,
   					HAVE_CONFIG_H,
   				);
  +				GCC_STRICT_ALIASING = YES;
   				GCC_TREAT_WARNINGS_AS_ERRORS = YES;
   				GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
   				GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
  @@ -1784,6 +1787,7 @@
   				INFOPLIST_FILE = Info.plist;
   				INSTALL_PATH = /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks;
   				MACOSX_DEPLOYMENT_TARGET = 10.3;
  +				OTHER_CFLAGS = "";
   				OTHER_LDFLAGS = (
   					"$(STYLE_LDFLAGS)",
   					"-sub_library",
  @@ -1828,6 +1832,7 @@
   					APPLE_CHANGES,
   					HAVE_CONFIG_H,
   				);
  +				GCC_STRICT_ALIASING = YES;
   				GCC_TREAT_WARNINGS_AS_ERRORS = YES;
   				GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
   				GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
  @@ -1835,6 +1840,7 @@
   				INFOPLIST_FILE = Info.plist;
   				INSTALL_PATH = /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks;
   				MACOSX_DEPLOYMENT_TARGET = 10.3;
  +				OTHER_CFLAGS = "";
   				OTHER_LDFLAGS = (
   					"$(STYLE_LDFLAGS)",
   					"-sub_library",
  @@ -1879,12 +1885,14 @@
   					APPLE_CHANGES,
   					HAVE_CONFIG_H,
   				);
  +				GCC_STRICT_ALIASING = YES;
   				GCC_TREAT_WARNINGS_AS_ERRORS = YES;
   				GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
   				GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
   				HEADER_SEARCH_PATHS = icu;
   				INFOPLIST_FILE = Info.plist;
   				INSTALL_PATH = /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks;
  +				OTHER_CFLAGS = "";
   				OTHER_LDFLAGS = (
   					"$(STYLE_LDFLAGS)",
   					"-sub_library",
  @@ -2276,6 +2284,9 @@
   		149C277208902AFE008A9EFC /* Development */ = {
   			isa = XCBuildConfiguration;
   			buildSettings = {
  +				GCC_ENABLE_OBJC_GC = YES;
  +				GCC_FAST_OBJC_DISPATCH = YES;
  +				GCC_STRICT_ALIASING = YES;
   				GCC_THREADSAFE_STATICS = NO;
   			};
   			name = Development;
  @@ -2283,6 +2294,10 @@
   		149C277308902AFE008A9EFC /* Deployment */ = {
   			isa = XCBuildConfiguration;
   			buildSettings = {
  +				GCC_ENABLE_OBJC_GC = YES;
  +				GCC_FAST_OBJC_DISPATCH = YES;
  +				GCC_OPTIMIZATION_LEVEL = s;
  +				GCC_STRICT_ALIASING = YES;
   				GCC_THREADSAFE_STATICS = NO;
   			};
   			name = Deployment;
  @@ -2290,6 +2305,9 @@
   		149C277408902AFE008A9EFC /* OptimizedWithSymbols */ = {
   			isa = XCBuildConfiguration;
   			buildSettings = {
  +				GCC_ENABLE_OBJC_GC = YES;
  +				GCC_FAST_OBJC_DISPATCH = YES;
  +				GCC_STRICT_ALIASING = YES;
   				GCC_THREADSAFE_STATICS = NO;
   			};
   			name = OptimizedWithSymbols;
  @@ -2297,6 +2315,9 @@
   		149C277508902AFE008A9EFC /* Default */ = {
   			isa = XCBuildConfiguration;
   			buildSettings = {
  +				GCC_ENABLE_OBJC_GC = YES;
  +				GCC_FAST_OBJC_DISPATCH = YES;
  +				GCC_STRICT_ALIASING = YES;
   				GCC_THREADSAFE_STATICS = NO;
   			};
   			name = Default;
  
  
  
  1.73      +36 -24    JavaScriptCore/kjs/nodes.cpp
  
  Index: nodes.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/nodes.cpp,v
  retrieving revision 1.72
  retrieving revision 1.73
  diff -u -r1.72 -r1.73
  --- nodes.cpp	12 Aug 2005 07:36:00 -0000	1.72
  +++ nodes.cpp	12 Aug 2005 23:20:48 -0000	1.73
  @@ -333,37 +333,43 @@
   // ECMA 11.1.2 & 10.1.4
   ValueImp *ResolveNode::evaluate(ExecState *exec)
   {
  -  ScopeChain chain = exec->context().imp()->scopeChain();
  -
  -  assert(!chain.isEmpty());
  +  const ScopeChain& chain = exec->context().imp()->scopeChain();
  +  ScopeChainIterator iter = chain.begin();
  +  ScopeChainIterator end = chain.end();
  +  
  +  // we must always have something in the scope chain
  +  assert(iter != end);
   
     PropertySlot slot;
     do { 
  -    ObjectImp *o = chain.top();
  +    ObjectImp *o = *iter;
   
       if (o->getPropertySlot(exec, ident, slot))
         return slot.getValue(exec, ident);
       
  -    chain.pop();
  -  } while (!chain.isEmpty());
  +    ++iter;
  +  } while (iter != end);
   
     return undefinedVariableError(exec, ident);
   }
   
   Reference ResolveNode::evaluateReference(ExecState *exec)
   {
  -  ScopeChain chain = exec->context().imp()->scopeChain();
  -
  -  assert(!chain.isEmpty());
  +  const ScopeChain& chain = exec->context().imp()->scopeChain();
  +  ScopeChainIterator iter = chain.begin();
  +  ScopeChainIterator end = chain.end();
  +  
  +  // we must always have something in the scope chain
  +  assert(iter != end);
   
     PropertySlot slot;
     do { 
  -    ObjectImp *o = chain.top();
  +    ObjectImp *o = *iter;
       if (o->getPropertySlot(exec, ident, slot))
         return Reference(o, ident);
       
  -    chain.pop();
  -  } while (!chain.isEmpty());
  +    ++iter;
  +  } while (iter != end);
   
     return Reference(ident);
   }
  @@ -817,14 +823,17 @@
   // ECMA 11.2.3
   ValueImp *FunctionCallResolveNode::evaluate(ExecState *exec)
   {
  -  ScopeChain chain = exec->context().imp()->scopeChain();
  -
  -  assert(!chain.isEmpty());
  +  const ScopeChain& chain = exec->context().imp()->scopeChain();
  +  ScopeChainIterator iter = chain.begin();
  +  ScopeChainIterator end = chain.end();
  +  
  +  // we must always have something in the scope chain
  +  assert(iter != end);
   
     PropertySlot slot;
     ObjectImp *base;
     do { 
  -    base = chain.top();
  +    base = *iter;
       if (base->getPropertySlot(exec, ident, slot)) {
         ValueImp *v = slot.getValue(exec, ident);
         KJS_CHECKEXCEPTIONVALUE
  @@ -854,8 +863,8 @@
   
         return func->call(exec, thisObj, argList);
       }
  -    chain.pop();
  -  } while (!chain.isEmpty());
  +    ++iter;
  +  } while (iter != end);
     
     return undefinedVariableError(exec, ident);
   }
  @@ -1679,19 +1688,22 @@
   
   ValueImp *AssignResolveNode::evaluate(ExecState *exec)
   {
  -  ScopeChain chain = exec->context().imp()->scopeChain();
  -
  -  assert(!chain.isEmpty());
  +  const ScopeChain& chain = exec->context().imp()->scopeChain();
  +  ScopeChainIterator iter = chain.begin();
  +  ScopeChainIterator end = chain.end();
  +  
  +  // we must always have something in the scope chain
  +  assert(iter != end);
   
     PropertySlot slot;
     ObjectImp *base;
     do { 
  -    base = chain.top();
  +    base = *iter;
       if (base->getPropertySlot(exec, m_ident, slot))
         goto found;
   
  -    chain.pop();
  -  } while (!chain.isEmpty());
  +    ++iter;
  +  } while (iter != end);
   
     if (m_oper != OpEqual)
       return undefinedVariableError(exec, m_ident);
  
  
  
  1.10      +21 -0     JavaScriptCore/kjs/scope_chain.h
  
  Index: scope_chain.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/scope_chain.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- scope_chain.h	14 Jul 2005 18:27:03 -0000	1.9
  +++ scope_chain.h	12 Aug 2005 23:20:48 -0000	1.10
  @@ -40,6 +40,24 @@
           int refCount;
       };
   
  +    class ScopeChainIterator {
  +    public:
  +        ScopeChainIterator(ScopeChainNode *node) : m_node(node) {}
  +
  +        ObjectImp * const & operator*() const { return m_node->object; }
  +        ObjectImp * const * operator->() const { return &(operator*()); }
  +    
  +        ScopeChainIterator& operator++() { m_node = m_node->next; return *this; }
  +
  +        // postfix ++ intentionally omitted
  +
  +        bool operator==(const ScopeChainIterator& other) const { return m_node == other.m_node; }
  +        bool operator!=(const ScopeChainIterator& other) const { return m_node != other.m_node; }
  +
  +    private:
  +        ScopeChainNode *m_node;
  +    };
  +
       class ScopeChain {
       public:
           ScopeChain() : _node(0) { }
  @@ -54,6 +72,9 @@
   
   	ObjectImp *bottom() const;
   
  +        ScopeChainIterator begin() const { return ScopeChainIterator(_node); }
  +        ScopeChainIterator end() const { return ScopeChainIterator(0); }
  +
           void clear() { deref(); _node = 0; }
           void push(ObjectImp *);
           void push(const ScopeChain &);
  
  
  



More information about the webkit-changes mailing list