Changeset 26892 in webkit for trunk/JavaScriptCore/kjs/value.cpp


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/value.cpp

    r24633 r26892  
    11/*
    2  *  This file is part of the KDE libraries
    32 *  Copyright (C) 1999-2001 Harri Porten ([email protected])
    43 *  Copyright (C) 2001 Peter Kelly ([email protected])
    5  *  Copyright (C) 2003 Apple Computer, Inc.
     4 *  Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
    65 *
    76 *  This library is free software; you can redistribute it and/or
     
    4241}
    4342
    44 bool JSCell::getUInt32(unsigned&) const
     43bool JSCell::getInt32(int32_t&) const
     44{
     45    return false;
     46}
     47
     48bool JSCell::getUInt32(uint32_t&) const
    4549{
    4650    return false;
     
    5660}
    5761
    58 int32_t JSValue::toInt32(ExecState* exec) const
    59 {
    60     bool ok;
    61     return toInt32(exec, ok);
    62 }
    63 
    64 int32_t JSValue::toInt32(ExecState* exec, bool& ok) const
     62int32_t JSValue::toInt32SlowCase(ExecState* exec, bool& ok) const
    6563{
    6664    ok = true;
    6765
    68     uint32_t i;
    69     if (getUInt32(i))
     66    int32_t i;
     67    if (getInt32(i))
    7068        return i;
    7169
    7270    double d = roundValue(exec, const_cast<JSValue*>(this));
     71    if (d >= -D32 / 2 && d < D32 / 2)
     72        return static_cast<int32_t>(d);
     73
    7374    if (isNaN(d) || isInf(d)) {
    7475        ok = false;
     
    8586}
    8687
    87 uint32_t JSValue::toUInt32(ExecState* exec) const
    88 {
    89     bool ok;
    90     return toUInt32(exec, ok);
    91 }
    92 
    93 uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const
     88uint32_t JSValue::toUInt32SlowCase(ExecState* exec, bool& ok) const
    9489{
    9590    ok = true;
     
    10095
    10196    double d = roundValue(exec, const_cast<JSValue*>(this));
     97    if (d >= 0.0 && d < D32)
     98        return static_cast<uint32_t>(d);
     99
    102100    if (isNaN(d) || isInf(d)) {
    103101        ok = false;
     
    119117
    120118    double d = roundValue(exec, const_cast<JSValue*>(this));
     119    if (d >= 0.0 && d < D16)
     120        return static_cast<uint16_t>(d);
     121
    121122    if (isNaN(d) || isInf(d))
    122123        return 0;
Note: See TracChangeset for help on using the changeset viewer.