Changeset 37333 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Oct 6, 2008, 10:50:08 AM (17 years ago)
Author:
[email protected]
Message:

2008-10-06 Maciej Stachowiak <[email protected]>

Reviewed by Sam Weinig.



1) Make JSValue::toBoolean nonvirtual and completely inline by
making use of the StructureID type field.


2) Make JSValue::toBoolean not take an ExecState; doesn't need it.


3) Make op_not, op_loop_if_true and op_jtrue not read the
ExecState (toBoolean doesn't need it any more) and not check
exceptions (toBoolean can't throw).

  • API/JSValueRef.cpp: (JSValueToBoolean):
  • JavaScriptCore.exp:
  • VM/CodeBlock.cpp: (JSC::CodeBlock::dump):
  • VM/Machine.cpp: (JSC::Machine::privateExecute): (JSC::Machine::cti_op_loop_if_true): (JSC::Machine::cti_op_not): (JSC::Machine::cti_op_jtrue):
  • kjs/ArrayPrototype.cpp: (JSC::arrayProtoFuncFilter): (JSC::arrayProtoFuncEvery): (JSC::arrayProtoFuncSome):
  • kjs/BooleanConstructor.cpp: (JSC::constructBoolean): (JSC::callBooleanConstructor):
  • kjs/GetterSetter.h:
  • kjs/JSCell.h: (JSC::JSValue::toBoolean):
  • kjs/JSNumberCell.cpp:
  • kjs/JSNumberCell.h: (JSC::JSNumberCell::toBoolean):
  • kjs/JSObject.cpp:
  • kjs/JSObject.h: (JSC::JSObject::toBoolean): (JSC::JSCell::toBoolean):
  • kjs/JSString.cpp:
  • kjs/JSString.h: (JSC::JSString::toBoolean):
  • kjs/JSValue.h:
  • kjs/RegExpConstructor.cpp: (JSC::setRegExpConstructorMultiline):
  • kjs/RegExpObject.cpp: (JSC::RegExpObject::match):
  • kjs/RegExpPrototype.cpp: (JSC::regExpProtoFuncToString):
Location:
trunk/JavaScriptCore
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSValueRef.cpp

    r37215 r37333  
    189189}
    190190
    191 bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
    192 {
    193     ExecState* exec = toJS(ctx);
    194     JSValue* jsValue = toJS(value);
    195     return jsValue->toBoolean(exec);
     191bool JSValueToBoolean(JSContextRef, JSValueRef value)
     192{
     193    return toJS(value)->toBoolean();
    196194}
    197195
  • trunk/JavaScriptCore/ChangeLog

    r37331 r37333  
     12008-10-06  Maciej Stachowiak  <[email protected]>
     2
     3        Reviewed by Sam Weinig.
     4       
     5        - optimize op_jtrue, op_loop_if_true and op_not in various ways
     6        https://bugs.webkit.org/show_bug.cgi?id=21404
     7       
     8        1) Make JSValue::toBoolean nonvirtual and completely inline by
     9        making use of the StructureID type field.
     10       
     11        2) Make JSValue::toBoolean not take an ExecState; doesn't need it.
     12       
     13        3) Make op_not, op_loop_if_true and op_jtrue not read the
     14        ExecState (toBoolean doesn't need it any more) and not check
     15        exceptions (toBoolean can't throw).
     16
     17        * API/JSValueRef.cpp:
     18        (JSValueToBoolean):
     19        * JavaScriptCore.exp:
     20        * VM/CodeBlock.cpp:
     21        (JSC::CodeBlock::dump):
     22        * VM/Machine.cpp:
     23        (JSC::Machine::privateExecute):
     24        (JSC::Machine::cti_op_loop_if_true):
     25        (JSC::Machine::cti_op_not):
     26        (JSC::Machine::cti_op_jtrue):
     27        * kjs/ArrayPrototype.cpp:
     28        (JSC::arrayProtoFuncFilter):
     29        (JSC::arrayProtoFuncEvery):
     30        (JSC::arrayProtoFuncSome):
     31        * kjs/BooleanConstructor.cpp:
     32        (JSC::constructBoolean):
     33        (JSC::callBooleanConstructor):
     34        * kjs/GetterSetter.h:
     35        * kjs/JSCell.h:
     36        (JSC::JSValue::toBoolean):
     37        * kjs/JSNumberCell.cpp:
     38        * kjs/JSNumberCell.h:
     39        (JSC::JSNumberCell::toBoolean):
     40        * kjs/JSObject.cpp:
     41        * kjs/JSObject.h:
     42        (JSC::JSObject::toBoolean):
     43        (JSC::JSCell::toBoolean):
     44        * kjs/JSString.cpp:
     45        * kjs/JSString.h:
     46        (JSC::JSString::toBoolean):
     47        * kjs/JSValue.h:
     48        * kjs/RegExpConstructor.cpp:
     49        (JSC::setRegExpConstructorMultiline):
     50        * kjs/RegExpObject.cpp:
     51        (JSC::RegExpObject::match):
     52        * kjs/RegExpPrototype.cpp:
     53        (JSC::regExpProtoFuncToString):
     54
    1552008-10-06  Ariya Hidayat  <[email protected]>
    256
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r37323 r37333  
    336336__ZNK3JSC8JSObject8toStringEPNS_9ExecStateE
    337337__ZNK3JSC8JSObject9classNameEv
    338 __ZNK3JSC8JSObject9toBooleanEPNS_9ExecStateE
    339338__ZNK3JSC9CodeBlock17derefStructureIDsEPNS_11InstructionE
    340339__ZNK3JSC9HashTable11createTableEPNS_12JSGlobalDataE
  • trunk/JavaScriptCore/VM/CodeBlock.cpp

    r37324 r37333  
    811811        }
    812812        case op_tear_off_activation: {
    813             int r0 = (++it)->u.operand;
    814             printf("[%4d] tear_off_activation\t %s\n", location, registerName(r0).c_str());
     813            printf("[%4d] tear_off_activation\n", location);
    815814            break;
    816815        }
    817816        case op_tear_off_arguments: {
    818             int r0 = (++it)->u.operand;
    819             printf("[%4d] tear_off_arguments\t %s\n", location, registerName(r0).c_str());
     817            printf("[%4d] tear_off_arguments\n", location);
    820818            break;
    821819        }
  • trunk/JavaScriptCore/VM/Machine.cpp

    r37325 r37333  
    21282128        int dst = (++vPC)->u.operand;
    21292129        int src = (++vPC)->u.operand;
    2130         JSValue* result = jsBoolean(!r[src].jsValue(exec)->toBoolean(exec));
    2131         VM_CHECK_EXCEPTION();
     2130        JSValue* result = jsBoolean(!r[src].jsValue(exec)->toBoolean());
    21322131        r[dst] = result;
    21332132
     
    29872986        int cond = (++vPC)->u.operand;
    29882987        int target = (++vPC)->u.operand;
    2989         if (r[cond].jsValue(exec)->toBoolean(exec)) {
     2988        if (r[cond].jsValue(exec)->toBoolean()) {
    29902989            vPC += target;
    29912990            CHECK_FOR_TIMEOUT();
     
    30043003        int cond = (++vPC)->u.operand;
    30053004        int target = (++vPC)->u.operand;
    3006         if (r[cond].jsValue(exec)->toBoolean(exec)) {
     3005        if (r[cond].jsValue(exec)->toBoolean()) {
    30073006            vPC += target;
    30083007            NEXT_OPCODE;
     
    30203019        int cond = (++vPC)->u.operand;
    30213020        int target = (++vPC)->u.operand;
    3022         if (!r[cond].jsValue(exec)->toBoolean(exec)) {
     3021        if (!r[cond].jsValue(exec)->toBoolean()) {
    30233022            vPC += target;
    30243023            NEXT_OPCODE;
     
    49894988    JSValue* src1 = ARG_src1;
    49904989
    4991     ExecState* exec = ARG_exec;
    4992 
    4993     bool result = src1->toBoolean(exec);
    4994     VM_CHECK_EXCEPTION_AT_END();
    4995     return result;
     4990    return src1->toBoolean();
    49964991}
    49974992
     
    51165111JSValue* Machine::cti_op_not(CTI_ARGS)
    51175112{
    5118     JSValue* src = ARG_src1;
    5119 
    5120     ExecState* exec = ARG_exec;
    5121 
    5122     JSValue* result = jsBoolean(!src->toBoolean(exec));
    5123     VM_CHECK_EXCEPTION_AT_END();
    5124     return result;
     5113    return jsBoolean(!ARG_src1->toBoolean());
    51255114}
    51265115
    51275116int SFX_CALL Machine::cti_op_jtrue(CTI_ARGS)
    51285117{
    5129     JSValue* src1 = ARG_src1;
    5130 
    5131     ExecState* exec = ARG_exec;
    5132 
    5133     bool result = src1->toBoolean(exec);
    5134     VM_CHECK_EXCEPTION_AT_END();
    5135     return result;
     5118    return ARG_src1->toBoolean();
    51365119}
    51375120
  • trunk/JavaScriptCore/kjs/ArrayPrototype.cpp

    r37175 r37333  
    583583        JSValue* result = call(exec, function, callType, callData, applyThis, eachArguments);
    584584
    585         if (result->toBoolean(exec))
     585        if (result->toBoolean())
    586586            resultArray->put(exec, filterIndex++, v);
    587587    }
     
    657657        eachArguments.append(thisObj);
    658658
    659         bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean(exec);
     659        bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean();
    660660
    661661        if (!predicateResult) {
     
    721721        eachArguments.append(thisObj);
    722722
    723         bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean(exec);
     723        bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean();
    724724
    725725        if (predicateResult) {
  • trunk/JavaScriptCore/kjs/BooleanConstructor.cpp

    r37257 r37333  
    4242{
    4343    BooleanObject* obj = new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanObjectStructure());
    44     obj->setInternalValue(jsBoolean(args.at(exec, 0)->toBoolean(exec)));
     44    obj->setInternalValue(jsBoolean(args.at(exec, 0)->toBoolean()));
    4545    return obj;
    4646}
     
    6060static JSValue* callBooleanConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
    6161{
    62     return jsBoolean(args.at(exec, 0)->toBoolean(exec));
     62    return jsBoolean(args.at(exec, 0)->toBoolean());
    6363}
    6464
  • trunk/JavaScriptCore/kjs/GetterSetter.h

    r36316 r37333  
    5353        virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const;
    5454        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
    55         virtual bool toBoolean(ExecState*) const;
     55        bool toBoolean(ExecState*) const;
    5656        virtual double toNumber(ExecState*) const;
    5757        virtual UString toString(ExecState*) const;
  • trunk/JavaScriptCore/kjs/JSCell.h

    r37285 r37333  
    7373        virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const = 0;
    7474        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*&) = 0;
    75         virtual bool toBoolean(ExecState*) const = 0;
     75        bool toBoolean() const;
    7676        virtual double toNumber(ExecState*) const = 0;
    7777        virtual UString toString(ExecState*) const = 0;
     
    273273    }
    274274
    275     inline bool JSValue::toBoolean(ExecState* exec) const
    276     {
    277         return JSImmediate::isImmediate(this) ? JSImmediate::toBoolean(this) : asCell()->toBoolean(exec);
     275    inline bool JSValue::toBoolean() const
     276    {
     277        return JSImmediate::isImmediate(this) ? JSImmediate::toBoolean(this) : asCell()->toBoolean();
    278278    }
    279279
  • trunk/JavaScriptCore/kjs/JSNumberCell.cpp

    r37257 r37333  
    3939    value = this;
    4040    return true;
    41 }
    42 
    43 bool JSNumberCell::toBoolean(ExecState*) const
    44 {
    45     return m_value < 0.0 || m_value > 0.0; // false for NaN
    4641}
    4742
  • trunk/JavaScriptCore/kjs/JSNumberCell.h

    r37285 r37333  
    5353        virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const;
    5454        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
    55         virtual bool toBoolean(ExecState*) const;
     55        bool toBoolean() const { return m_value < 0.0 || m_value > 0.0; /* false for NaN */ }
    5656        virtual double toNumber(ExecState*) const;
    5757        virtual UString toString(ExecState*) const;
  • trunk/JavaScriptCore/kjs/JSObject.cpp

    r37297 r37333  
    431431}
    432432
    433 bool JSObject::toBoolean(ExecState*) const
    434 {
    435     return true;
    436 }
    437 
    438433double JSObject::toNumber(ExecState* exec) const
    439434{
  • trunk/JavaScriptCore/kjs/JSObject.h

    r37068 r37333  
    2929#include "ExecState.h"
    3030#include "JSNumberCell.h"
     31#include "JSString.h"
    3132#include "PropertyMap.h"
    3233#include "PropertySlot.h"
     
    110111        virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
    111112        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
    112         virtual bool toBoolean(ExecState*) const;
     113        bool toBoolean() const { return true; }
    113114        virtual double toNumber(ExecState*) const;
    114115        virtual UString toString(ExecState*) const;
     
    245246    }
    246247    return false;
     248}
     249
     250inline bool JSCell::toBoolean() const
     251{
     252    JSType type = structureID()->typeInfo().type();
     253    if (type == NumberType)
     254        return static_cast<const JSNumberCell*>(this)->toBoolean();
     255    if (type == ObjectType)
     256        return static_cast<const JSObject*>(this)->toBoolean();
     257    ASSERT(type == StringType);
     258    return static_cast<const JSString*>(this)->toBoolean();
    247259}
    248260
  • trunk/JavaScriptCore/kjs/JSString.cpp

    r37257 r37333  
    4141    number = m_value.toDouble();
    4242    return false;
    43 }
    44 
    45 bool JSString::toBoolean(ExecState*) const
    46 {
    47     return !m_value.isEmpty();
    4843}
    4944
  • trunk/JavaScriptCore/kjs/JSString.h

    r37285 r37333  
    9393        static PassRefPtr<StructureID> createStructureID(JSValue* proto) { return StructureID::create(proto, TypeInfo(StringType, NeedsThisConversion)); }
    9494
     95        bool toBoolean() const { return !m_value.isEmpty(); }
     96
    9597    private:
    9698        enum VPtrStealingHackType { VPtrStealingHack };
     
    102104        virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const;
    103105        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
    104         virtual bool toBoolean(ExecState*) const;
    105106        virtual double toNumber(ExecState*) const;
    106107        virtual JSObject* toObject(ExecState*) const;
  • trunk/JavaScriptCore/kjs/JSValue.h

    r37285 r37333  
    9797        bool getPrimitiveNumber(ExecState*, double& number, JSValue*&);
    9898
    99         bool toBoolean(ExecState*) const;
     99        bool toBoolean() const;
    100100
    101101        // toNumber conversion is expected to be side effect free if an exception has
  • trunk/JavaScriptCore/kjs/RegExpConstructor.cpp

    r37257 r37333  
    312312}
    313313
    314 void setRegExpConstructorMultiline(ExecState* exec, JSObject* baseObject, JSValue* value)
    315 {
    316     static_cast<RegExpConstructor*>(baseObject)->setMultiline(value->toBoolean(exec));
     314void setRegExpConstructorMultiline(ExecState*, JSObject* baseObject, JSValue* value)
     315{
     316    static_cast<RegExpConstructor*>(baseObject)->setMultiline(value->toBoolean());
    317317}
    318318 
  • trunk/JavaScriptCore/kjs/RegExpObject.cpp

    r36977 r37333  
    122122    }
    123123
    124     bool global = get(exec, exec->propertyNames().global)->toBoolean(exec);
     124    bool global = get(exec, exec->propertyNames().global)->toBoolean();
    125125    int lastIndex = 0;
    126126    if (global) {
  • trunk/JavaScriptCore/kjs/RegExpPrototype.cpp

    r36726 r37333  
    107107    UString result = "/" + static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().source)->toString(exec);
    108108    result.append('/');
    109     if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().global)->toBoolean(exec))
     109    if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().global)->toBoolean())
    110110        result.append('g');
    111     if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().ignoreCase)->toBoolean(exec))
     111    if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().ignoreCase)->toBoolean())
    112112        result.append('i');
    113     if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().multiline)->toBoolean(exec))
     113    if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().multiline)->toBoolean())
    114114        result.append('m');
    115115    return jsNontrivialString(exec, result);
Note: See TracChangeset for help on using the changeset viewer.