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


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.h

    r26690 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-2005 Apple Computer, Inc.
     4 *  Copyright (C) 2003, 2004, 2005, 2007 Apple Inc. All rights reserved.
    65 *
    76 *  This library is free software; you can redistribute it and/or
     
    2928#include "ustring.h"
    3029#include <stddef.h> // for size_t
     30#include <wtf/AlwaysInline.h>
    3131
    3232namespace KJS {
     
    7777
    7878    // Extracting integer values.
     79    bool getInt32(int32_t&) const;
    7980    bool getUInt32(uint32_t&) const;
    8081
     
    102103
    103104private:
     105    int32_t toInt32SlowCase(ExecState*, bool& ok) const;
     106    uint32_t toUInt32SlowCase(ExecState*, bool& ok) const;
     107
    104108    // Implementation details.
    105109    JSCell *asCell();
     
    137141
    138142    // Extracting integer values.
     143    virtual bool getInt32(int32_t&) const;
    139144    virtual bool getUInt32(uint32_t&) const;
    140145
     
    165170extern const double Inf;
    166171
    167 
    168172inline JSValue *jsUndefined()
    169173{
     
    186190}
    187191
    188 inline JSValue *jsNumber(double d)
     192ALWAYS_INLINE JSValue* jsNumber(double d)
    189193{
    190194    JSValue *v = JSImmediate::fromDouble(d);
     
    329333}
    330334
     335inline bool JSValue::getInt32(int32_t& v) const
     336{
     337    return JSImmediate::isImmediate(this) ? JSImmediate::toInt32(this, v) : asCell()->getInt32(v);
     338}
     339
    331340inline bool JSValue::getUInt32(uint32_t& v) const
    332341{
    333     if (JSImmediate::isImmediate(this)) {
    334         double d = JSImmediate::toDouble(this);
    335         if (!(d >= 0) || d > 0xFFFFFFFFUL) // true for NaN
    336             return false;
    337         v = static_cast<uint32_t>(d);
    338         return JSImmediate::isNumber(this);
    339     }
    340     return asCell()->getUInt32(v);
     342    return JSImmediate::isImmediate(this) ? JSImmediate::toUInt32(this, v) : asCell()->getUInt32(v);
    341343}
    342344
     
    382384}
    383385
     386ALWAYS_INLINE int32_t JSValue::toInt32(ExecState* exec) const
     387{
     388    int32_t i;
     389    if (JSImmediate::isImmediate(this) && JSImmediate::toInt32(this, i))
     390        return i;
     391    bool ok;
     392    return toInt32SlowCase(exec, ok);
     393}
     394
     395inline uint32_t JSValue::toUInt32(ExecState* exec) const
     396{
     397    uint32_t i;
     398    if (JSImmediate::isImmediate(this) && JSImmediate::toUInt32(this, i))
     399        return i;
     400    bool ok;
     401    return toUInt32SlowCase(exec, ok);
     402}
     403
     404inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const
     405{
     406    int32_t i;
     407    if (JSImmediate::isImmediate(this) && JSImmediate::toInt32(this, i)) {
     408        ok = true;
     409        return i;
     410    }
     411    return toInt32SlowCase(exec, ok);
     412}
     413
     414inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const
     415{
     416    uint32_t i;
     417    if (JSImmediate::isImmediate(this) && JSImmediate::toUInt32(this, i)) {
     418        ok = true;
     419        return i;
     420    }
     421    return toUInt32SlowCase(exec, ok);
     422}
     423
    384424} // namespace
    385425
Note: See TracChangeset for help on using the changeset viewer.