Ignore:
Timestamp:
Oct 22, 2007, 11:44:27 PM (18 years ago)
Author:
darin
Message:

Reviewed by Maciej.

This should restore correctness and make speed better too, restoring some
of the optimization we lost in my last check-in.

  • kjs/JSImmediate.h: (KJS::JSImmediate::getTruncatedInt32): Added. Uses the range checking idiom I used in my patch yesterday. (KJS::JSImmediate::getTruncatedUInt32): Ditto.
  • kjs/internal.h: Removed getInt32 and added getTruncatedInt/UInt32.
  • kjs/internal.cpp: (KJS::NumberImp::getUInt32): Changed to always use double, since I can't find a way to write this more efficiently for float. (KJS::NumberImp::getTruncatedInt32): Added. (KJS::NumberImp::getTruncatedUInt32): Added.
  • kjs/value.h: Removed getInt32 and added getTruncatedInt/UInt32. (KJS::JSValue::getUInt32): (KJS::JSValue::getTruncatedInt32): Added. (KJS::JSValue::getTruncatedUInt32): Added. (KJS::JSValue::toInt32): Changed getInt32 call to getTruncatedInt32. (KJS::JSValue::toUInt32): Changed getUInt32 call to getTruncatedUInt32.
  • kjs/value.cpp: (KJS::JSCell::getTruncatedInt32): Added. (KJS::JSCell::getTruncatedUInt32): Added. (KJS::JSValue::toInteger): Changed getUInt32 call to getTruncatedInt32. (KJS::JSValue::toInt32SlowCase): Removed extra getInt32 call I accidentally had left in here. (KJS::JSValue::toUInt32SlowCase): Ditto. (KJS::JSValue::toUInt16): Changed getUInt32 call to getTruncatedUInt32.
File:
1 edited

Legend:

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

    r26899 r26912  
    8888    static JSType type(const JSValue*);
    8989
    90     static bool getInt32(const JSValue*, int32_t&);
    9190    static bool getUInt32(const JSValue*, uint32_t&);
     91    static bool getTruncatedInt32(const JSValue*, int32_t&);
     92    static bool getTruncatedUInt32(const JSValue*, uint32_t&);
    9293
    9394    // It would nice just to use fromDouble() to create these values, but that would prevent them from
     
    163164    }
    164165
    165     static double toDouble(const JSValue* v)
     166    static float toFloat(const JSValue* v)
    166167    {
    167168        ASSERT(isImmediate(v));
     
    172173    }
    173174
    174     static bool getInt32(const JSValue* v, int32_t& i)
    175     {
    176         ASSERT(isImmediate(v));
    177 
    178         FloatUnion floatUnion;
    179         floatUnion.asBits = static_cast<uint32_t>(unTag(v));
    180         float f = floatUnion.asFloat;
     175    static double toDouble(const JSValue* v)
     176    {
     177        return toFloat(v);
     178    }
     179
     180    static bool getTruncatedInt32(const JSValue* v, int32_t& i)
     181    {
     182        float f = toFloat(v);
     183        if (!(f >= -2147483648.0F && f < 2147483648.0F))
     184            return false;
    181185        i = static_cast<int32_t>(f);
    182         return isNumber(v) && i == f;
    183     }
    184 
    185     static bool getUInt32(const JSValue* v, uint32_t& i)
    186     {
    187         ASSERT(isImmediate(v));
    188 
    189         FloatUnion floatUnion;
    190         floatUnion.asBits = static_cast<uint32_t>(unTag(v));
    191         float f = floatUnion.asFloat;
     186        return isNumber(v);
     187    }
     188
     189    static bool getTruncatedUInt32(const JSValue* v, uint32_t& i)
     190    {
     191        float f = toFloat(v);
     192        if (!(f >= 0.0F && f < 4294967296.0F))
     193            return false;
    192194        i = static_cast<uint32_t>(f);
    193         return isNumber(v) && i == f;
     195        return isNumber(v);
    194196    }
    195197};
     
    221223    }
    222224
    223     static bool getInt32(const JSValue* v, int32_t& i)
     225    static bool getTruncatedInt32(const JSValue* v, int32_t& i)
    224226    {
    225227        double d = toDouble(v);
     228        if (!(d >= -2147483648.0 && d < 2147483648.0))
     229            return false;
    226230        i = static_cast<int32_t>(d);
    227         return isNumber(v) && i == d;
    228     }
    229 
    230     static bool getUInt32(const JSValue* v, uint32_t& i)
     231        return isNumber(v);
     232    }
     233
     234    static bool getTruncatedUInt32(const JSValue* v, uint32_t& i)
    231235    {
    232236        double d = toDouble(v);
     237        if (!(d >= 0.0 && d < 4294967296.0))
     238            return false;
    233239        i = static_cast<uint32_t>(d);
    234         return isNumber(v) && i == d;
     240        return isNumber(v);
    235241    }
    236242};
     
    263269}
    264270
    265 inline bool JSImmediate::getInt32(const JSValue* v, int32_t& i)
    266 {
    267     return FPBitValues<is32bit, is64bit>::getInt32(v, i);
    268 }
    269 
    270271inline bool JSImmediate::getUInt32(const JSValue* v, uint32_t& i)
    271272{
    272     return FPBitValues<is32bit, is64bit>::getUInt32(v, i);
     273    double d = toDouble(v);
     274    i = static_cast<uint32_t>(d);
     275    return isNumber(v) && i == d;
     276}
     277
     278inline bool JSImmediate::getTruncatedInt32(const JSValue* v, int32_t& i)
     279{
     280    return FPBitValues<is32bit, is64bit>::getTruncatedInt32(v, i);
     281}
     282
     283inline bool JSImmediate::getTruncatedUInt32(const JSValue* v, uint32_t& i)
     284{
     285    return FPBitValues<is32bit, is64bit>::getTruncatedUInt32(v, i);
    273286}
    274287
Note: See TracChangeset for help on using the changeset viewer.