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

    r26688 r26892  
    11/*
    2  *  This file is part of the KDE libraries
    32 *  Copyright (C) 1999-2002 Harri Porten ([email protected])
    43 *  Copyright (C) 2001 Peter Kelly ([email protected])
    5  *  Copyright (C) 2004 Apple Computer, Inc.
     4 *  Copyright (C) 2004, 2007 Apple Inc. All rights reserved.
    65 *
    76 *  This library is free software; you can redistribute it and/or
     
    113112}
    114113
    115 // FIXME: We can optimize this to work like JSValue::getUInt32. I'm ignoring it for now
    116 // because it never shows up on profiles.
     114bool NumberImp::getInt32(int32_t& int32) const
     115{
     116    if (!(val >= -2147483648.0 && val < 2147483648.0))
     117        return false;
     118    int32 = static_cast<int32_t>(val);
     119    return true;
     120}
     121
    117122bool NumberImp::getUInt32(uint32_t& uint32) const
    118123{
    119   uint32 = (uint32_t)val;
    120   return (double)uint32 == val;
     124    if (!(val >= 0.0 && val < 4294967296.0))
     125        return false;
     126    uint32 = static_cast<uint32_t>(val);
     127    return true;
    121128}
    122129
Note: See TracChangeset for help on using the changeset viewer.