Changeset 12728 in webkit for trunk/JavaScriptCore/kjs/internal.h


Ignore:
Timestamp:
Feb 9, 2006, 10:42:01 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by mjs.

  • Fixed <rdar://problem/4343730> Should switch ConstantValues (null, undefined, true, false) from JS objects to immediate values similar to SimpleNumber

2.0% performance gain on my new super-accurate version of JS iBench.
(I promise to land a version of it soon.)

The gist of the change:
(1) The SimpleNumber class (simple_number.h) is now the JSImmediate
class (JSImmediate.h/.cpp), and it handles not only numbers but also
null, undefined, true, and false.
(2) JSImmediate provides convenience methods for the bit masking
necessary to encode and decode immediate values.
(3) ConstantValues, BooleanImp, NullImp, and UndefinedImp are gone.
(4) JSCell no longer implements functions like getBoolean, because
only a JSImmediate can be a boolean.
(5) JSImmediate no longer uses ALWAYS_INLINE because there's no need,
and ALWAYS_INLINE is a non-portable option of last resort.
(6) Type is now JSType, and it resides in its own file, JSType.h.
Since I was there, I did some header include sorting as part of this
change.

The rest pretty much explains itself.

  • JavaScriptCore.xcodeproj/project.pbxproj: Removed simple_number.h, added JSImmediate.h/.cpp.
  • bindings/c/c_instance.cpp: (KJS::Bindings::CInstance::defaultValue):
  • bindings/c/c_instance.h:
  • bindings/c/c_utility.cpp: (KJS::Bindings::convertValueToNPVariant):
  • bindings/jni/jni_instance.cpp: (JavaInstance::defaultValue):
  • bindings/jni/jni_instance.h:
  • bindings/jni/jni_jsobject.cpp: (JavaJSObject::convertValueToJObject):
  • bindings/objc/WebScriptObject.mm: (+[WebScriptObject _convertValueToObjcValue:originExecutionContext:executionContext:]): Standardized calls to use getXXX instead of hand-rolling JSValue functionality.
  • bindings/objc/objc_instance.h:
  • bindings/objc/objc_instance.mm: (ObjcInstance::getValueOfUndefinedField): (ObjcInstance::defaultValue):
  • bindings/objc/objc_runtime.h:
  • bindings/objc/objc_runtime.mm: (ObjcFallbackObjectImp::type): (ObjcFallbackObjectImp::defaultValue):
  • bindings/runtime.h: (KJS::Bindings::Instance::getValueOfUndefinedField):
  • bindings/runtime_object.cpp: (RuntimeObjectImp::defaultValue):
  • bindings/runtime_object.h:
  • kjs/JSImmediate.h: Added. (KJS::JSImmediate::isImmediate): (KJS::JSImmediate::isNumber): (KJS::JSImmediate::isBoolean): (KJS::JSImmediate::isUndefinedOrNull): (KJS::JSImmediate::fromDouble): (KJS::JSImmediate::toDouble): (KJS::JSImmediate::toBoolean): (KJS::JSImmediate::trueImmediate): (KJS::JSImmediate::falseImmediate): (KJS::JSImmediate::NaNImmediate): (KJS::JSImmediate::undefinedImmediate): (KJS::JSImmediate::nullImmediate): (KJS::JSImmediate::tag): (KJS::JSImmediate::unTag): (KJS::JSImmediate::getTag): (KJS::JSImmediate::): (KJS::JSImmediate::isIEEE): (KJS::JSImmediate::is32bit): (KJS::JSImmediate::is64bit): (KJS::JSImmediate::NanAsBits): (KJS::JSImmediate::zeroAsBits): (KJS::JSImmediate::oneAsBits):
  • kjs/JSLock.cpp: (KJS::JSLock::lock): Removed hack-o-rama to initialize ConstantValues.
  • kjs/JSType.h: Added.
  • kjs/collector.cpp: (KJS::Collector::protect): (KJS::Collector::unprotect): (KJS::Collector::collect):
  • kjs/internal.cpp: (KJS::StringImp::toPrimitive): (KJS::NumberImp::toPrimitive): (KJS::NumberImp::toBoolean): (KJS::GetterSetterImp::toPrimitive):
  • kjs/internal.h: (KJS::StringImp::type): (KJS::NumberImp::type):
  • kjs/object.cpp: (KJS::JSObject::type): (KJS::tryGetAndCallProperty): Replaced "Are you one of the six things I'm looking for?" test with "Are you not the one thing I'm not looking for" test. (KJS::JSObject::defaultValue): (KJS::JSObject::toPrimitive):
  • kjs/object.h: (KJS::GetterSetterImp::type): (KJS::JSValue::isObject):
  • kjs/operations.cpp: (KJS::equal): (KJS::strictEqual): (KJS::add):
  • kjs/reference.cpp: (KJS::Reference::deleteValue):
  • kjs/simple_number.h: Removed.
  • kjs/string_object.cpp: (StringInstance::getOwnPropertySlot): fixed indentation
  • kjs/value.cpp: (KJS::JSValue::toObject): (KJS::jsNumberCell): New function to quarantine a PIC branch -- allows us to inline jsNumber without adding PIC branches to callers.
  • kjs/value.h: (KJS::jsUndefined): (KJS::jsNull): (KJS::jsNaN): (KJS::jsBoolean): (KJS::jsNumber): (KJS::JSValue::downcast): (KJS::JSValue::isUndefinedOrNull): (KJS::JSValue::isBoolean): (KJS::JSValue::isNumber): (KJS::JSValue::isString): (KJS::JSValue::isObject): (KJS::JSValue::getBoolean): (KJS::JSValue::getNumber): (KJS::JSValue::getString): (KJS::JSValue::getObject): (KJS::JSValue::getUInt32): (KJS::JSValue::mark): Replaced !JSImmediate::is() test with assertion, resulting in a slight performance gain. Callers should always check !marked() before calling mark(), so it's impossible to call mark on a JSImmediate. (KJS::JSValue::marked): (KJS::JSValue::type): (KJS::JSValue::toPrimitive): (KJS::JSValue::toBoolean): (KJS::JSValue::toNumber): (KJS::JSValue::toString):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/internal.h

    r12593 r12728  
    2626#define INTERNAL_H
    2727
    28 #include "ustring.h"
     28#include "JSType.h"
     29#include "interpreter.h"
    2930#include "object.h"
    3031#include "protect.h"
     32#include "scope_chain.h"
    3133#include "types.h"
    32 #include "interpreter.h"
    33 #include "scope_chain.h"
     34#include "ustring.h"
     35
    3436#include <kxmlcore/Noncopyable.h>
    3537#include <kxmlcore/RefPtr.h>
     
    5052  // ---------------------------------------------------------------------------
    5153
    52   class UndefinedImp : public JSCell {
    53   public:
    54     Type type() const { return UndefinedType; }
    55 
    56     JSValue *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
     54  class StringImp : public JSCell {
     55  public:
     56    StringImp(const UString& v) : val(v) { }
     57    UString value() const { return val; }
     58
     59    JSType type() const { return StringType; }
     60
     61    JSValue *toPrimitive(ExecState *exec, JSType preferred = UnspecifiedType) const;
    5762    bool toBoolean(ExecState *exec) const;
    5863    double toNumber(ExecState *exec) const;
    5964    UString toString(ExecState *exec) const;
    6065    JSObject *toObject(ExecState *exec) const;
    61   };
    62 
    63   class NullImp : public JSCell {
    64   public:
    65     Type type() const { return NullType; }
    66 
    67     JSValue *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
    68     bool toBoolean(ExecState *exec) const;
    69     double toNumber(ExecState *exec) const;
    70     UString toString(ExecState *exec) const;
    71     JSObject *toObject(ExecState *exec) const;
    72   };
    73 
    74   class BooleanImp : public JSCell {
    75   public:
    76     BooleanImp(bool v = false) : val(v) { }
    77     bool value() const { return val; }
    78 
    79     Type type() const { return BooleanType; }
    80 
    81     JSValue *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
    82     bool toBoolean(ExecState *exec) const;
    83     double toNumber(ExecState *exec) const;
    84     UString toString(ExecState *exec) const;
    85     JSObject *toObject(ExecState *exec) const;
    86 
    87   private:
    88     bool val;
    89   };
    90  
    91   class StringImp : public JSCell {
    92   public:
    93     StringImp(const UString& v) : val(v) { }
    94     UString value() const { return val; }
    95 
    96     Type type() const { return StringType; }
    97 
    98     JSValue *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
    99     bool toBoolean(ExecState *exec) const;
    100     double toNumber(ExecState *exec) const;
    101     UString toString(ExecState *exec) const;
    102     JSObject *toObject(ExecState *exec) const;
    10366
    10467  private:
     
    10972    friend class ConstantValues;
    11073    friend class InterpreterImp;
    111     friend JSValue *jsNumber(double);
     74    friend JSValue *jsNumberCell(double);
    11275  public:
    11376    double value() const { return val; }
    11477
    115     Type type() const { return NumberType; }
    116 
    117     JSValue *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
     78    JSType type() const { return NumberType; }
     79
     80    JSValue *toPrimitive(ExecState *exec, JSType preferred = UnspecifiedType) const;
    11881    bool toBoolean(ExecState *exec) const;
    11982    double toNumber(ExecState *exec) const;
Note: See TracChangeset for help on using the changeset viewer.