Ignore:
Timestamp:
Sep 15, 2008, 11:08:51 PM (17 years ago)
Author:
[email protected]
Message:

2008-09-15 Maciej Stachowiak <[email protected]>

Reviewed by Cameron Zwarich.


  • speed up the === and !== operators by choosing the fast cases better


No effect on SunSpider but speeds up the V8 EarlyBoyer benchmark about 4%.

  • VM/Machine.cpp: (JSC::Machine::privateExecute): (JSC::Machine::cti_op_stricteq): (JSC::Machine::cti_op_nstricteq):
  • kjs/JSImmediate.h: (JSC::JSImmediate::areBothImmediate):
  • kjs/operations.cpp: (JSC::strictEqual): (JSC::strictEqualSlowCase):
  • kjs/operations.h:
File:
1 edited

Legend:

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

    r36263 r36483  
    102102bool strictEqual(JSValue* v1, JSValue* v2)
    103103{
     104    if (JSImmediate::areBothImmediate(v1, v2))
     105        return v1 == v2;
     106
     107    if (JSImmediate::isEitherImmediate(v1, v2) & v1 != JSImmediate::from(0) & v2 != JSImmediate::from(0))
     108        return false;
     109
     110    return strictEqualSlowCase(v1, v2);
     111}
     112
     113bool strictEqualSlowCase(JSValue* v1, JSValue* v2)
     114{
     115    ASSERT(!JSImmediate::areBothImmediate(v1, v2));
     116
    104117    if (JSImmediate::isEitherImmediate(v1, v2)) {
    105         if (v1 == v2)
    106             return true;
     118        // pointers can't be equal since one is immediate and one isn't
     119        ASSERT(v1 != v2);
     120        ASSERT(v1 == JSImmediate::zeroImmediate() || v2 == JSImmediate::zeroImmediate());
    107121
    108122        // The reason we can't just return false here is that 0 === -0,
    109123        // and while the former is an immediate number, the latter is not.
    110         if (v1 == JSImmediate::from(0))
    111             return !JSImmediate::isImmediate(v2)
    112                 && static_cast<JSCell*>(v2)->isNumber()
    113                 && static_cast<JSNumberCell*>(v2)->value() == 0;
    114         return v2 == JSImmediate::from(0)
    115             && !JSImmediate::isImmediate(v1)
    116             && static_cast<JSCell*>(v1)->isNumber()
    117             && static_cast<JSNumberCell*>(v1)->value() == 0;
     124        if (v1 == JSImmediate::zeroImmediate())
     125            return static_cast<JSCell*>(v2)->isNumber() && static_cast<JSNumberCell*>(v2)->value() == 0;
     126        return static_cast<JSCell*>(v1)->isNumber() && static_cast<JSNumberCell*>(v1)->value() == 0;
    118127    }
    119128
    120     if (static_cast<JSCell*>(v1)->isNumber())
     129    if (static_cast<JSCell*>(v1)->isNumber()) {
    121130        return static_cast<JSCell*>(v2)->isNumber()
    122131            && static_cast<JSNumberCell*>(v1)->value() == static_cast<JSNumberCell*>(v2)->value();
     132    }
    123133
    124     if (static_cast<JSCell*>(v1)->isString())
     134    if (static_cast<JSCell*>(v1)->isString()) {
    125135        return static_cast<JSCell*>(v2)->isString()
    126136            && static_cast<JSString*>(v1)->value() == static_cast<JSString*>(v2)->value();
     137    }
    127138
    128139    return v1 == v2;
Note: See TracChangeset for help on using the changeset viewer.