Changeset 50705 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Nov 9, 2009, 7:14:26 PM (16 years ago)
Author:
[email protected]
Message:

Added a tiny cache for Date parsing.

Reviewed by Sam "Home Wrecker" Weinig.

SunSpider says 1.2% faster.

  • runtime/DateConversion.cpp:

(JSC::parseDate): Try to reuse the last parsed Date, if present.

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::resetDateCache):

  • runtime/JSGlobalData.h: Added storage for last parsed Date. Refactored

this code to make resetting the date cache easier.

  • runtime/JSGlobalObject.h:

(JSC::DynamicGlobalObjectScope::DynamicGlobalObjectScope): Updated for
refactoring.

  • wtf/DateMath.cpp:

(JSC::parseDateFromNullTerminatedCharacters):

  • wtf/DateMath.h: Changed ExecState to be first parameter, as is the JSC custom.
Location:
trunk/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r50704 r50705  
     12009-11-09  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Sam "Home Wrecker" Weinig.
     4
     5        Added a tiny cache for Date parsing.
     6       
     7        SunSpider says 1.2% faster.
     8
     9        * runtime/DateConversion.cpp:
     10        (JSC::parseDate): Try to reuse the last parsed Date, if present.
     11
     12        * runtime/JSGlobalData.cpp:
     13        (JSC::JSGlobalData::resetDateCache):
     14        * runtime/JSGlobalData.h: Added storage for last parsed Date. Refactored
     15        this code to make resetting the date cache easier.
     16
     17        * runtime/JSGlobalObject.h:
     18        (JSC::DynamicGlobalObjectScope::DynamicGlobalObjectScope): Updated for
     19        refactoring.
     20
     21        * wtf/DateMath.cpp:
     22        (JSC::parseDateFromNullTerminatedCharacters):
     23        * wtf/DateMath.h: Changed ExecState to be first parameter, as is the JSC custom.
     24
    1252009-11-09  Oliver Hunt  <[email protected]>
    226
  • trunk/JavaScriptCore/runtime/DateConversion.cpp

    r50608 r50705  
    4444#include "DateConversion.h"
    4545
     46#include "CallFrame.h"
    4647#include "UString.h"
    4748#include <wtf/DateMath.h>
     
    5455double parseDate(ExecState* exec, const UString &date)
    5556{
    56     return parseDateFromNullTerminatedCharacters(date.UTF8String().c_str(), exec);
     57    if (date == exec->globalData().cachedDateString)
     58        return exec->globalData().cachedDateStringValue;
     59    double value = parseDateFromNullTerminatedCharacters(exec, date.UTF8String().c_str());
     60    exec->globalData().cachedDateString = date;
     61    exec->globalData().cachedDateStringValue = value;
     62    return value;
    5763}
    5864
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r50608 r50705  
    253253}
    254254
     255void JSGlobalData::resetDateCache()
     256{
     257    cachedUTCOffset = NaN;
     258    cachedDateString = UString();
     259}
     260
    255261void JSGlobalData::startSampling()
    256262{
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r50608 r50705  
    156156        double cachedUTCOffset;
    157157
     158        UString cachedDateString;
     159        double cachedDateStringValue;
     160
    158161#ifndef NDEBUG
    159162        bool mainThreadOnly;
    160163#endif
     164
     165        void resetDateCache();
    161166
    162167        void startSampling();
  • trunk/JavaScriptCore/runtime/JSGlobalObject.h

    r50608 r50705  
    446446                m_dynamicGlobalObjectSlot = dynamicGlobalObject;
    447447
    448                 // Reset the UTC cache between JS invocations to force the VM
     448                // Reset the date cache between JS invocations to force the VM
    449449                // to observe time zone changes.
    450                 callFrame->globalData().cachedUTCOffset = NaN;
     450                callFrame->globalData().resetDateCache();
    451451            }
    452452        }
  • trunk/JavaScriptCore/wtf/DateMath.cpp

    r50634 r50705  
    874874}
    875875
    876 double parseDateFromNullTerminatedCharacters(const char* dateString, ExecState* exec)
     876double parseDateFromNullTerminatedCharacters(ExecState* exec, const char* dateString)
    877877{
    878878    ASSERT(exec);
  • trunk/JavaScriptCore/wtf/DateMath.h

    r50634 r50705  
    8686double gregorianDateTimeToMS(ExecState*, const GregorianDateTime&, double, bool inputIsUTC);
    8787double getUTCOffset(ExecState*);
    88 double parseDateFromNullTerminatedCharacters(const char* dateString, ExecState*);
     88double parseDateFromNullTerminatedCharacters(ExecState*, const char* dateString);
    8989
    9090// Intentionally overridding the default tm of the system.
Note: See TracChangeset for help on using the changeset viewer.