Ignore:
Timestamp:
Oct 22, 2007, 11:39:46 AM (18 years ago)
Author:
darin
Message:

Reviewed by Eric Seidel.

Makes SunSpider 6% faster.

  • kjs/JSImmediate.h: Added toInt32 and toUInt32, with separate versions for 32-bit and 64-bit.
  • kjs/value.h: (KJS::JSValue::getUInt32): Call JSImmediate::toUInt32.
  • kjs/internal.h: Added getInt32.
  • kjs/internal.cpp: (KJS::NumberImp::getInt32): Added. (KJS::NumberImp::getUInt32): Replaced with more-optimal implementation stolen from JSValue.
  • kjs/value.h: (KJS::jsNumber): Marked ALWAYS_INLINE, because this wasn't getting inlined. (KJS::JSValue::getInt32): Added. (KJS::JSValue::getUInt32): Changed to call the new JSImmediate::toUInt32 to avoid converting from float to double. (KJS::JSValue::toInt32): Made inline, separated out the slow case. (KJS::JSValue::toUInt32): Ditto.
  • kjs/value.cpp: (KJS::JSCell::getInt32): Added. (KJS::JSValue::toInt32SlowCase): Renamed from toInt32. Changed to use the new getInt32. Added a faster case for in-range numbers. (KJS::JSValue::toUInt32SlowCase): Ditto. (KJS::JSValue::toUInt16): Added a faster case for in-range numbers.
File:
1 edited

Legend:

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

    r26589 r26892  
    11/*
    2  *  This file is part of the KDE libraries
    3  *  Copyright (C) 2003-2006 Apple Computer, Inc
     2 *  Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
    43 *  Copyright (C) 2006 Alexey Proskuryakov ([email protected])
    54 *
     
    8382
    8483    static JSValue* fromDouble(double d);
    85     static double toDouble(const JSValue* v);
    86     static bool toBoolean(const JSValue* v);
     84    static double toDouble(const JSValue*);
     85    static bool toBoolean(const JSValue*);
    8786    static JSObject* toObject(const JSValue*, ExecState*);
    8887    static UString toString(const JSValue*);
    8988    static JSType type(const JSValue*);
    90    
     89
     90    static bool toInt32(const JSValue*, int32_t&);
     91    static bool toUInt32(const JSValue*, uint32_t&);
     92
    9193    // It would nice just to use fromDouble() to create these values, but that would prevent them from
    9294    // turning into compile-time constants.
     
    170172        return floatUnion.asFloat;
    171173    }
     174
     175    static bool toInt32(const JSValue* v, int32_t& i)
     176    {
     177        ASSERT(isImmediate(v));
     178
     179        FloatUnion floatUnion;
     180        floatUnion.asBits = static_cast<uint32_t>(unTag(v));
     181        float f = floatUnion.asFloat;
     182        if (!(f >= -2147483648.0F && f < 2147483648.0F))
     183            return false;
     184        i = static_cast<int32_t>(f);
     185        return isNumber(v);
     186    }
     187
     188    static bool toUInt32(const JSValue* v, uint32_t& i)
     189    {
     190        ASSERT(isImmediate(v));
     191
     192        FloatUnion floatUnion;
     193        floatUnion.asBits = static_cast<uint32_t>(unTag(v));
     194        float f = floatUnion.asFloat;
     195        if (!(f >= 0.0F && f < 4294967296.0F))
     196            return false;
     197        i = static_cast<uint32_t>(f);
     198        return isNumber(v);
     199    }
    172200};
    173201
     
    196224        doubleUnion.asBits = unTag(v);
    197225        return doubleUnion.asDouble;
     226    }
     227
     228    static bool toInt32(const JSValue* v, int32_t& i)
     229    {
     230        double d = toDouble(v);
     231        if (!(d >= -2147483648.0 && d < 2147483648.0))
     232            return false;
     233        i = static_cast<int32_t>(d);
     234        return isNumber(v);
     235    }
     236
     237    static bool toUInt32(const JSValue* v, uint32_t& i)
     238    {
     239        double d = toDouble(v);
     240        if (!(d >= 0.0 && d < 4294967296.0))
     241            return false;
     242        i = static_cast<uint32_t>(d);
     243        return isNumber(v);
    198244    }
    199245};
     
    226272}
    227273
     274inline bool JSImmediate::toInt32(const JSValue* v, int32_t& i)
     275{
     276    return FPBitValues<is32bit, is64bit>::toInt32(v, i);
     277}
     278
     279inline bool JSImmediate::toUInt32(const JSValue* v, uint32_t& i)
     280{
     281    return FPBitValues<is32bit, is64bit>::toUInt32(v, i);
     282}
     283
    228284} // namespace KJS
    229285
Note: See TracChangeset for help on using the changeset viewer.