Ignore:
Timestamp:
Jul 25, 2005, 3:17:20 PM (20 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Darin.

  • 10% speedup on JavaScript iBench
  • 5% speedup on 24fun BenchJS benchmark

Changed all get methods to getOwnProperty - they are no longer
responsible for prototype lookup, and determine if the property
was found as a side efect.

get() is now a nonvirtual ObjectImp method which calls the virtual
getOwnProperty and walks the prototype chain. A few selected
methods were inlined.

Changed ResolveNode::evaluate plus some other places to use
getProperty which does get() and hasProperty() in one lookup.

Also miscellaneous code cleanup.

  • bindings/objc/objc_runtime.h:
  • bindings/objc/objc_runtime.mm: (ObjcFallbackObjectImp::ObjcFallbackObjectImp): (ObjcFallbackObjectImp::getOwnProperty):
  • bindings/runtime_array.cpp: (RuntimeArrayImp::RuntimeArrayImp): (RuntimeArrayImp::getOwnProperty):
  • bindings/runtime_array.h:
  • bindings/runtime_method.cpp: (RuntimeMethodImp::getOwnProperty):
  • bindings/runtime_method.h:
  • bindings/runtime_object.cpp: (RuntimeObjectImp::getOwnProperty):
  • bindings/runtime_object.h:
  • kjs/array_instance.h:
  • kjs/array_object.cpp: (ArrayInstanceImp::getOwnProperty): (ArrayPrototypeImp::getOwnProperty): (ArrayProtoFuncImp::call):
  • kjs/array_object.h:
  • kjs/date_object.cpp: (DatePrototypeImp::getOwnProperty):
  • kjs/date_object.h:
  • kjs/function.cpp: (KJS::FunctionImp::getOwnProperty): (KJS::ArgumentsImp::getOwnProperty): (KJS::ActivationImp::getOwnProperty):
  • kjs/function.h:
  • kjs/lookup.h: (KJS::lookupGetOwnProperty): (KJS::lookupGetOwnFunction): (KJS::lookupGetOwnValue):
  • kjs/math_object.cpp: (MathObjectImp::getOwnProperty): (MathObjectImp::getValueProperty):
  • kjs/math_object.h:
  • kjs/nodes.cpp: (ResolveNode::evaluate):
  • kjs/number_object.cpp: (NumberObjectImp::getOwnProperty):
  • kjs/number_object.h:
  • kjs/object.cpp: (KJS::ObjectImp::get): (KJS::ObjectImp::getOwnProperty): (KJS::ObjectImp::getProperty):
  • kjs/object.h: (KJS::ObjectImp::getProperty): (KJS::ObjectImp::getOwnProperty):
  • kjs/object_object.cpp: (ObjectProtoFuncImp::call):
  • kjs/regexp_object.cpp: (RegExpObjectImp::getOwnProperty):
  • kjs/regexp_object.h:
  • kjs/string_object.cpp: (StringInstanceImp::getOwnProperty): (StringPrototypeImp::getOwnProperty):
  • kjs/string_object.h:

WebCore:

Reviewed by Darin.

  • 10% speedup on JavaScript iBench
  • 5% speedup on 24fun BenchJS benchmark

Changed all get methods to getOwnProperty - they are no longer responsible for
prototype lookup, and determine if the property was found as a side efect.

Also miscellaneous code cleanup.

  • khtml/ecma/kjs_css.cpp: (KJS::DOMCSSStyleDeclaration::getOwnProperty): (KJS::DOMStyleSheet::getOwnProperty): (KJS::DOMStyleSheetList::getOwnProperty): (KJS::DOMMediaList::getOwnProperty): (KJS::DOMCSSStyleSheet::getOwnProperty): (KJS::DOMCSSRuleList::getOwnProperty): (KJS::DOMCSSRule::getOwnProperty): (KJS::DOMCSSRule::getValueProperty): (KJS::CSSRuleConstructor::getOwnProperty): (KJS::DOMCSSValue::getOwnProperty): (KJS::CSSValueConstructor::getOwnProperty): (KJS::DOMCSSPrimitiveValue::getOwnProperty): (KJS::CSSPrimitiveValueConstructor::getOwnProperty): (KJS::DOMCSSValueList::getOwnProperty): (KJS::DOMRGBColor::getOwnProperty): (KJS::DOMRect::getOwnProperty): (KJS::DOMCounter::getOwnProperty):
  • khtml/ecma/kjs_css.h:
  • khtml/ecma/kjs_dom.cpp: (KJS::DOMNode::getOwnProperty): (KJS::DOMNodeList::getOwnProperty): (KJS::DOMAttr::getOwnProperty): (KJS::DOMDocument::getOwnProperty): (KJS::DOMElement::getOwnProperty): (KJS::DOMDocumentType::getOwnProperty): (KJS::DOMNamedNodeMap::getOwnProperty): (KJS::DOMProcessingInstruction::getOwnProperty): (KJS::DOMNotation::getOwnProperty): (KJS::DOMEntity::getOwnProperty): (KJS::NodeConstructor::getOwnProperty): (KJS::DOMExceptionConstructor::getOwnProperty): (KJS::DOMNamedNodesCollection::getOwnProperty): (KJS::DOMCharacterData::getOwnProperty):
  • khtml/ecma/kjs_dom.h:
  • khtml/ecma/kjs_events.cpp: (KJS::EventConstructor::getOwnProperty): (KJS::DOMEvent::getOwnProperty): (KJS::EventExceptionConstructor::getOwnProperty): (KJS::DOMUIEvent::getOwnProperty): (KJS::DOMMouseEvent::getOwnProperty): (KJS::DOMKeyboardEvent::getOwnProperty): (KJS::MutationEventConstructor::getOwnProperty): (KJS::DOMMutationEvent::getOwnProperty): (KJS::DOMWheelEvent::getOwnProperty): (KJS::Clipboard::getOwnProperty):
  • khtml/ecma/kjs_events.h:
  • khtml/ecma/kjs_html.cpp: (KJS::HTMLDocument::getOwnProperty): (KJS::KJS::HTMLElement::getOwnProperty): (KJS::KJS::HTMLCollection::getOwnProperty): (KJS::KJS::HTMLSelectCollection::getOwnProperty): (KJS::Image::getOwnProperty): (KJS::Context2D::getOwnProperty): (KJS::Gradient::getOwnProperty): (KJS::ImagePattern::getOwnProperty):
  • khtml/ecma/kjs_html.h:
  • khtml/ecma/kjs_navigator.cpp: (KJS::Plugin::Plugin): (KJS::Navigator::getOwnProperty): (KJS::Plugins::getOwnProperty): (KJS::MimeTypes::getOwnProperty): (KJS::Plugin::getOwnProperty): (KJS::MimeType::getOwnProperty):
  • khtml/ecma/kjs_navigator.h:
  • khtml/ecma/kjs_range.cpp: (KJS::DOMRange::getOwnProperty): (KJS::RangeConstructor::getOwnProperty):
  • khtml/ecma/kjs_range.h:
  • khtml/ecma/kjs_traversal.cpp: (KJS::DOMNodeIterator::getOwnProperty): (KJS::NodeFilterConstructor::getOwnProperty): (KJS::DOMTreeWalker::getOwnProperty):
  • khtml/ecma/kjs_traversal.h:
  • khtml/ecma/kjs_views.cpp: (KJS::DOMAbstractView::getOwnProperty):
  • khtml/ecma/kjs_views.h:
  • khtml/ecma/kjs_window.cpp: (KJS::Screen::getOwnProperty): (KJS::Window::~Window): (KJS::Window::getOwnProperty): (KJS::Window::put): (KJS::FrameArray::getOwnProperty): (KJS::Location::Location): (KJS::Location::getOwnProperty): (KJS::Location::put): (KJS::Selection::Selection): (KJS::Selection::getOwnProperty): (KJS::BarInfo::getOwnProperty): (KJS::History::getOwnProperty):
  • khtml/ecma/kjs_window.h:
  • khtml/ecma/xmlhttprequest.cpp: (KJS::XMLHttpRequest::getOwnProperty):
  • khtml/ecma/xmlhttprequest.h:
File:
1 edited

Legend:

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

    r9842 r9889  
    7171}
    7272
    73 Value ArrayInstanceImp::get(ExecState *exec, const Identifier &propertyName) const
    74 {
    75   if (propertyName == lengthPropertyName)
    76     return Number(length);
     73bool ArrayInstanceImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const
     74{
     75  if (propertyName == lengthPropertyName) {
     76    result = Number(length);
     77    return true;
     78  }
    7779
    7880  bool ok;
     
    8082  if (ok) {
    8183    if (index >= length)
    82       return Undefined();
     84      return false;
    8385    if (index < storageLength) {
    8486      ValueImp *v = storage[index];
    85       return v ? Value(v) : Undefined();
    86     }
    87   }
    88 
    89   return ObjectImp::get(exec, propertyName);
    90 }
    91 
    92 Value ArrayInstanceImp::get(ExecState *exec, unsigned index) const
     87      if (!v || v == UndefinedImp::staticUndefined)
     88        return false;
     89
     90      result = Value(v);
     91      return true;
     92    }
     93  }
     94
     95  return ObjectImp::getOwnProperty(exec, propertyName, result);
     96}
     97
     98bool ArrayInstanceImp::getOwnProperty(ExecState *exec, unsigned index, Value& result) const
    9399{
    94100  if (index >= length)
    95     return Undefined();
     101    return false;
    96102  if (index < storageLength) {
    97103    ValueImp *v = storage[index];
    98     return v ? Value(v) : Undefined();
    99   }
    100  
    101   return ObjectImp::get(exec, Identifier::from(index));
     104    if (!v || v == UndefinedImp::staticUndefined)
     105      return false;
     106
     107    result = Value(v);
     108    return true;
     109  }
     110 
     111  return ObjectImp::getOwnProperty(exec, Identifier::from(index), result);
    102112}
    103113
     
    419429}
    420430
    421 Value ArrayPrototypeImp::get(ExecState *exec, const Identifier &propertyName) const
    422 {
    423   //fprintf( stderr, "ArrayPrototypeImp::get(%s)\n", propertyName.ascii() );
    424   return lookupGetFunction<ArrayProtoFuncImp, ArrayInstanceImp>( exec, propertyName, &arrayTable, this );
     431bool ArrayPrototypeImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const
     432{
     433  return lookupGetOwnFunction<ArrayProtoFuncImp, ArrayInstanceImp>(exec, propertyName, &arrayTable, this, result);
    425434}
    426435
     
    445454{
    446455  unsigned int length = thisObj.get(exec,lengthPropertyName).toUInt32(exec);
     456  ObjectImp *thisImp = thisObj.imp();
    447457
    448458  Value result;
     
    502512        length = curObj.get(exec,lengthPropertyName).toUInt32(exec);
    503513        while (k < length) {
    504           if (curObj.hasProperty(exec,k))
    505             arr.put(exec, n, curObj.get(exec, k));
     514          Value v;
     515          if (curObj.imp()->getProperty(exec, k, v))
     516            arr.put(exec, n, v);
    506517          n++;
    507518          k++;
     
    545556    for (unsigned int k = 0; k < middle; k++) {
    546557      unsigned lk1 = length - k - 1;
    547       Value obj = thisObj.get(exec,k);
    548       Value obj2 = thisObj.get(exec,lk1);
    549       if (thisObj.hasProperty(exec,lk1)) {
    550         if (thisObj.hasProperty(exec,k)) {
    551           thisObj.put(exec, k, obj2);
    552           thisObj.put(exec, lk1, obj);
    553         } else {
    554           thisObj.put(exec, k, obj2);
    555           thisObj.deleteProperty(exec, lk1);
    556         }
    557       } else {
    558         if (thisObj.hasProperty(exec, k)) {
    559           thisObj.deleteProperty(exec, k);
    560           thisObj.put(exec, lk1, obj);
    561         } else {
    562           // why delete something that's not there ? Strange.
    563           thisObj.deleteProperty(exec, k);
    564           thisObj.deleteProperty(exec, lk1);
    565         }
    566       }
     558      Value obj;
     559      Value obj2;
     560      bool has2 = thisImp->getProperty(exec, lk1, obj2);
     561      bool has1 = thisImp->getProperty(exec, k, obj);
     562
     563      if (has2)
     564        thisObj.put(exec, k, obj2);
     565      else
     566        thisObj.deleteProperty(exec, k);
     567
     568      if (has1)
     569        thisObj.put(exec, lk1, obj);
     570      else
     571        thisObj.deleteProperty(exec, lk1);
    567572    }
    568573    result = thisObj;
     
    576581      result = thisObj.get(exec, 0);
    577582      for(unsigned int k = 1; k < length; k++) {
    578         if (thisObj.hasProperty(exec, k)) {
    579           Value obj = thisObj.get(exec, k);
     583        Value obj;
     584        if (thisImp->getProperty(exec, k, obj))
    580585          thisObj.put(exec, k-1, obj);
    581         } else
     586        else
    582587          thisObj.deleteProperty(exec, k-1);
    583588      }
     
    623628    int e = static_cast<int>(end);
    624629    for(int k = b; k < e; k++, n++) {
    625       if (thisObj.hasProperty(exec, k)) {
    626         Value obj = thisObj.get(exec, k);
     630      Value obj;
     631      if (thisImp->getProperty(exec, k, obj))
    627632        resObj.put(exec, n, obj);
    628       }
    629633    }
    630634    resObj.put(exec, lengthPropertyName, Number(n), DontEnum | DontDelete);
     
    646650      }
    647651   
    648     if (thisObj.imp()->classInfo() == &ArrayInstanceImp::info) {
     652    if (thisImp->classInfo() == &ArrayInstanceImp::info) {
    649653      if (useSortFunction)
    650         ((ArrayInstanceImp *)thisObj.imp())->sort(exec, sortFunction);
     654        ((ArrayInstanceImp *)thisImp)->sort(exec, sortFunction);
    651655      else
    652         ((ArrayInstanceImp *)thisObj.imp())->sort(exec);
     656        ((ArrayInstanceImp *)thisImp)->sort(exec);
    653657      result = thisObj;
    654658      break;
     
    719723    //printf( "Splicing from %d, deleteCount=%d \n", begin, deleteCount );
    720724    for(unsigned int k = 0; k < deleteCount; k++) {
    721       if (thisObj.hasProperty(exec,k+begin)) {
    722         Value obj = thisObj.get(exec, k+begin);
     725      Value obj;
     726      if (thisImp->getProperty(exec, k+begin, obj))
    723727        resObj.put(exec, k, obj);
    724       }
    725728    }
    726729    resObj.put(exec, lengthPropertyName, Number(deleteCount), DontEnum | DontDelete);
     
    733736        for ( unsigned int k = begin; k < length - deleteCount; ++k )
    734737        {
    735           if (thisObj.hasProperty(exec,k+deleteCount)) {
    736             Value obj = thisObj.get(exec, k+deleteCount);
     738          Value obj;
     739          if (thisImp->getProperty(exec, k+deleteCount, obj))
    737740            thisObj.put(exec, k+additionalArgs, obj);
    738           }
    739741          else
    740742            thisObj.deleteProperty(exec, k+additionalArgs);
     
    747749        for ( unsigned int k = length - deleteCount; (int)k > begin; --k )
    748750        {
    749           if (thisObj.hasProperty(exec,k+deleteCount-1)) {
    750             Value obj = thisObj.get(exec, k+deleteCount-1);
    751             thisObj.put(exec, k+additionalArgs-1, obj);
    752           }
     751          Value obj;
     752          if (thisImp->getProperty(exec, k + deleteCount - 1, obj))
     753            thisObj.put(exec, k + additionalArgs - 1, obj);
    753754          else
    754755            thisObj.deleteProperty(exec, k+additionalArgs-1);
     
    767768    for ( unsigned int k = length; k > 0; --k )
    768769    {
    769       if (thisObj.hasProperty(exec,k-1)) {
    770         Value obj = thisObj.get(exec, k-1);
     770      Value obj;
     771      if (thisImp->getProperty(exec, k - 1, obj))
    771772        thisObj.put(exec, k+nrArgs-1, obj);
    772       } else {
     773      else
    773774        thisObj.deleteProperty(exec, k+nrArgs-1);
    774       }
    775775    }
    776776    for ( unsigned int k = 0; k < nrArgs; ++k )
Note: See TracChangeset for help on using the changeset viewer.