Changeset 50789 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Nov 10, 2009, 11:22:30 PM (16 years ago)
Author:
[email protected]
Message:

Faster Math.random, based on GameRand.

Reviewed by Gavin "avGni arBalroguch" Barraclough.

SunSpider says 1.4% faster.

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):

  • runtime/JSGlobalData.h: Use an object to track random number generation

state, initialized to the current time.

  • runtime/MathObject.cpp:

(JSC::MathObject::MathObject):
(JSC::mathProtoFuncRandom): Use the new hotness.

  • runtime/WeakRandom.h: Added.

(JSC::WeakRandom::WeakRandom):
(JSC::WeakRandom::get):
(JSC::WeakRandom::advance): The new hotness.

Location:
trunk/JavaScriptCore/runtime
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r50711 r50789  
    149149    , markStack(vptrSet.jsArrayVPtr)
    150150    , cachedUTCOffset(NaN)
     151    , weakRandom(static_cast<int>(currentTime()))
    151152#ifndef NDEBUG
    152153    , mainThreadOnly(false)
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r50711 r50789  
    3939#include "SmallStrings.h"
    4040#include "TimeoutChecker.h"
     41#include "WeakRandom.h"
    4142#include <wtf/Forward.h>
    4243#include <wtf/HashMap.h>
     
    179180        UString cachedDateString;
    180181        double cachedDateStringValue;
     182       
     183        WeakRandom weakRandom;
    181184
    182185#ifndef NDEBUG
  • trunk/JavaScriptCore/runtime/MathObject.cpp

    r48836 r50789  
    9797    putDirectWithoutTransition(Identifier(exec, "SQRT1_2"), jsNumber(exec, sqrt(0.5)), DontDelete | DontEnum | ReadOnly);
    9898    putDirectWithoutTransition(Identifier(exec, "SQRT2"), jsNumber(exec, sqrt(2.0)), DontDelete | DontEnum | ReadOnly);
    99     WTF::initializeWeakRandomNumberGenerator();
    10099}
    101100
     
    212211JSValue JSC_HOST_CALL mathProtoFuncRandom(ExecState* exec, JSObject*, JSValue, const ArgList&)
    213212{
    214     return jsNumber(exec, WTF::weakRandomNumber());
     213    return jsNumber(exec, exec->globalData().weakRandom.get());
    215214}
    216215
Note: See TracChangeset for help on using the changeset viewer.