2010-08-19 Andreas Kling <andreas.kling@nokia.com>

        Reviewed by Geoffrey Garen.

        JSC: Move the static_cast into to(U)Int32 fast case
        https://bugs.webkit.org/show_bug.cgi?id=44037

        Do the static_cast<(u)int32_t> inline to avoid the function call overhead
        for easily converted values (within (u)int32_t range.)

        * runtime/JSValue.cpp:
        (JSC::toInt32SlowCase):
        (JSC::toUInt32SlowCase):
        * runtime/JSValue.h:
        (JSC::JSValue::toInt32):
        (JSC::JSValue::toUInt32):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65698 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f270d94c
2010-08-19 Andreas Kling <andreas.kling@nokia.com>
Reviewed by Geoffrey Garen.
JSC: Move the static_cast into to(U)Int32 fast case
https://bugs.webkit.org/show_bug.cgi?id=44037
Do the static_cast<(u)int32_t> inline to avoid the function call overhead
for easily converted values (within (u)int32_t range.)
* runtime/JSValue.cpp:
(JSC::toInt32SlowCase):
(JSC::toUInt32SlowCase):
* runtime/JSValue.h:
(JSC::JSValue::toInt32):
(JSC::JSValue::toUInt32):
2010-08-18 Andreas Kling <andreas.kling@nokia.com>
Reviewed by Geoffrey Garen.
......
......@@ -137,16 +137,13 @@ char* JSValue::description()
int32_t toInt32SlowCase(double d, bool& ok)
{
ok = true;
if (d >= -D32 / 2 && d < D32 / 2)
return static_cast<int32_t>(d);
if (isnan(d) || isinf(d)) {
ok = false;
return 0;
}
ok = true;
double d32 = fmod(trunc(d), D32);
if (d32 >= D32 / 2)
d32 -= D32;
......@@ -157,16 +154,13 @@ int32_t toInt32SlowCase(double d, bool& ok)
uint32_t toUInt32SlowCase(double d, bool& ok)
{
ok = true;
if (d >= 0.0 && d < D32)
return static_cast<uint32_t>(d);
if (isnan(d) || isinf(d)) {
ok = false;
return 0;
}
ok = true;
double d32 = fmod(trunc(d), D32);
if (d32 < 0)
d32 += D32;
......
......@@ -397,16 +397,28 @@ namespace JSC {
{
if (isInt32())
return asInt32();
double val = toNumber(exec);
if (val >= -2147483648.0 && val < 2147483648.0)
return static_cast<int32_t>(val);
bool ignored;
return toInt32SlowCase(toNumber(exec), ignored);
return toInt32SlowCase(val, ignored);
}
inline uint32_t JSValue::toUInt32(ExecState* exec) const
{
if (isUInt32())
return asInt32();
double val = toNumber(exec);
if (val >= 0.0 && val < 4294967296.0)
return static_cast<uint32_t>(val);
bool ignored;
return toUInt32SlowCase(toNumber(exec), ignored);
return toUInt32SlowCase(val, ignored);
}
inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const
......@@ -415,7 +427,15 @@ namespace JSC {
ok = true;
return asInt32();
}
return toInt32SlowCase(toNumber(exec), ok);
double val = toNumber(exec);
if (val >= -2147483648.0 && val < 2147483648.0) {
ok = true;
return static_cast<int32_t>(val);
}
return toInt32SlowCase(val, ok);
}
inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const
......@@ -424,7 +444,15 @@ namespace JSC {
ok = true;
return asInt32();
}
return toUInt32SlowCase(toNumber(exec), ok);
double val = toNumber(exec);
if (val >= 0.0 && val < 4294967296.0) {
ok = true;
return static_cast<uint32_t>(val);
}
return toUInt32SlowCase(val, ok);
}
#if USE(JSVALUE32_64)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment