Changeset 50789 in webkit


Ignore:
Timestamp:
Nov 10, 2009 11:22:30 PM (14 years ago)
Author:
ggaren@apple.com
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
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r50711 r50789  
     12009-11-10  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Gavin "avGni arBalroguch" Barraclough.
     4
     5        Faster Math.random, based on GameRand.
     6       
     7        SunSpider says 1.4% faster.
     8
     9        * GNUmakefile.am:
     10        * JavaScriptCore.gypi:
     11        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
     12        * JavaScriptCore.xcodeproj/project.pbxproj: Added the header to the project.
     13
     14        * runtime/JSGlobalData.cpp:
     15        (JSC::JSGlobalData::JSGlobalData):
     16        * runtime/JSGlobalData.h: Use an object to track random number generation
     17        state, initialized to the current time.
     18
     19        * runtime/MathObject.cpp:
     20        (JSC::MathObject::MathObject):
     21        (JSC::mathProtoFuncRandom): Use the new hotness.
     22
     23        * runtime/WeakRandom.h: Added.
     24        (JSC::WeakRandom::WeakRandom):
     25        (JSC::WeakRandom::get):
     26        (JSC::WeakRandom::advance): The new hotness.
     27
    1282009-11-09  Geoffrey Garen  <ggaren@apple.com>
    229
  • trunk/JavaScriptCore/GNUmakefile.am

    r50174 r50789  
    499499        JavaScriptCore/runtime/UString.cpp \
    500500        JavaScriptCore/runtime/UString.h \
     501        JavaScriptCore/runtime/WeakRandom.h \
    501502        JavaScriptCore/wtf/FastAllocBase.h \
    502503        JavaScriptCore/wtf/FastMalloc.cpp \
  • trunk/JavaScriptCore/JavaScriptCore.gypi

    r50174 r50789  
    333333            'runtime/UString.cpp',
    334334            'runtime/UString.h',
     335            'runtime/WeakRandom.h',
    335336            'wrec/CharacterClass.cpp',
    336337            'wrec/CharacterClass.h',
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj

    r50608 r50789  
    12111211                        <File
    12121212                                RelativePath="..\..\runtime\UString.h"
     1213                                >
     1214                        </File>
     1215                        <File
     1216                                RelativePath="..\..\runtime\WeakRandom.h"
    12131217                                >
    12141218                        </File>
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r50179 r50789  
    5252                141211310A48794D00480255 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932F5BD90822A1C700736975 /* JavaScriptCore.framework */; };
    5353                141211340A48795800480255 /* minidom.c in Sources */ = {isa = PBXBuildFile; fileRef = 141211020A48780900480255 /* minidom.c */; };
     54                1420BE7B10AA6DDB00F455D2 /* WeakRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 1420BE7A10AA6DDB00F455D2 /* WeakRandom.h */; };
    5455                1421359B0A677F4F00A8195E /* JSBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1421359A0A677F4F00A8195E /* JSBase.cpp */; };
    5556                14280823107EC02C0013E7B2 /* Debugger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F692A8580255597D01FF60F7 /* Debugger.cpp */; };
     
    562563                141211200A48793C00480255 /* minidom */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = minidom; sourceTree = BUILT_PRODUCTS_DIR; };
    563564                1419D32C0CEA7CDE00FF507A /* RefCounted.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefCounted.h; sourceTree = "<group>"; };
     565                1420BE7A10AA6DDB00F455D2 /* WeakRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakRandom.h; sourceTree = "<group>"; };
    564566                1421359A0A677F4F00A8195E /* JSBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSBase.cpp; sourceTree = "<group>"; };
    565567                142711380A460BBB0080EEEA /* JSBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBase.h; sourceTree = "<group>"; };
     
    15941596                                F692A8850255597D01FF60F7 /* UString.cpp */,
    15951597                                F692A8860255597D01FF60F7 /* UString.h */,
     1598                                1420BE7A10AA6DDB00F455D2 /* WeakRandom.h */,
    15961599                        );
    15971600                        path = runtime;
     
    20032006                                148CD1D8108CF902008163C6 /* JSContextRefPrivate.h in Headers */,
    20042007                                14A1563210966365006FA260 /* DateInstanceCache.h in Headers */,
     2008                                1420BE7B10AA6DDB00F455D2 /* WeakRandom.h in Headers */,
    20052009                        );
    20062010                        runOnlyForDeploymentPostprocessing = 0;
  • 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.