Changeset 50590 in webkit for trunk/JavaScriptCore/wtf/DateMath.h


Ignore:
Timestamp:
Nov 5, 2009, 10:26:47 PM (16 years ago)
Author:
[email protected]
Message:

JavaScriptCore: https://bugs.webkit.org/show_bug.cgi?id=31197
Implemented a timezone cache not based on Mac OS X's notify_check API.

Patch by Geoffrey Garen <[email protected]> on 2009-11-05
Reviewed by Oliver Hunt.

If the VM calculates the local timezone offset from UTC, it caches the
result until the end of the current VM invocation. (We don't want to cache
forever, because the user's timezone may change over time.)

This removes notify_* overhead on Mac, and, more significantly, removes
OS time and date call overhead on non-Mac platforms.

~8% speedup on Date microbenchmark on Mac. SunSpider reports maybe a tiny
speedup on Mac. (Speedup on non-Mac platforms should be even more noticeable.)

  • interpreter/CachedCall.h:

(JSC::CachedCall::CachedCall):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::execute):

  • runtime/JSGlobalObject.h:

(JSC::DynamicGlobalObjectScope::DynamicGlobalObjectScope): Made the
DynamicGlobalObjectScope constructor responsible for checking whether a
dynamicGlobalObject has already been set. This eliminated some duplicate
client code, and allowed me to avoid adding even more duplicate client
code. Made DynamicGlobalObjectScope responsible for resetting the
local timezone cache upon first entry to the VM.

  • runtime/DateConstructor.cpp:

(JSC::constructDate):
(JSC::callDate):
(JSC::dateParse):
(JSC::dateUTC):

  • runtime/DateConversion.cpp:

(JSC::parseDate):

  • runtime/DateConversion.h:
  • runtime/DateInstance.cpp:

(JSC::DateInstance::gregorianDateTime):

  • runtime/DateInstance.h:
  • runtime/DateInstanceCache.h:
  • runtime/DatePrototype.cpp:

(JSC::setNewValueFromTimeArgs):
(JSC::setNewValueFromDateArgs):
(JSC::dateProtoFuncSetYear):

  • runtime/InitializeThreading.cpp:

(JSC::initializeThreadingOnce):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):

  • runtime/JSGlobalData.h:
  • wtf/DateMath.cpp:

(WTF::getCurrentUTCTime):
(WTF::getCurrentUTCTimeWithMicroseconds):
(WTF::getLocalTime):
(JSC::getUTCOffset): Use the new cache. Also, see below.
(JSC::gregorianDateTimeToMS):
(JSC::msToGregorianDateTime):
(JSC::initializeDates):
(JSC::parseDateFromNullTerminatedCharacters): Simplified the way this function
accounts for the local timezone offset, to accomodate our new caching API,
and a (possibly misguided) caller in WebCore. Also, see below.

  • wtf/DateMath.h:

(JSC::GregorianDateTime::GregorianDateTime): Moved most of the code in
DateMath.* into the JSC namespace. The code needed to move so it could
naturally interact with ExecState and JSGlobalData to support caching.
Logically, it seemed right to move it, too, since this code is not really
as low-level as the WTF namespace might imply -- it implements a set of
date parsing and conversion quirks that are finely tuned to the JavaScript
language. Also removed the Mac OS X notify_* infrastructure.

WebCore: https://bugs.webkit.org/show_bug.cgi?id=31197
Implemented a timezone cache not based on Mac OS X's notify_check API.

Patch by Geoffrey Garen <[email protected]> on 2009-11-05
Updated for JavaScriptCore internal API change.

  • platform/network/HTTPParsers.cpp:

(WebCore::parseDate): Pass 0 for ExecState, since we don't have one.
(This function probably shouldn't be using a JavaScript date parser
to begin with, but oh well.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/DateMath.h

    r49734 r50590  
    4646#include <string.h>
    4747#include <wtf/Noncopyable.h>
     48#include <wtf/UnusedParam.h>
    4849
    4950namespace WTF {
     51    double getCurrentUTCTime();
     52    double getCurrentUTCTimeWithMicroseconds();
     53    void getLocalTime(const time_t*, tm*);
     54}
    5055
     56namespace JSC {
     57
     58class ExecState;
    5159struct GregorianDateTime;
    5260
    5361void initializeDates();
    54 void msToGregorianDateTime(double, bool outputIsUTC, GregorianDateTime&);
    55 double gregorianDateTimeToMS(const GregorianDateTime&, double, bool inputIsUTC);
    56 double getUTCOffset();
     62void msToGregorianDateTime(ExecState*, double, bool outputIsUTC, GregorianDateTime&);
     63double gregorianDateTimeToMS(ExecState*, const GregorianDateTime&, double, bool inputIsUTC);
     64double getUTCOffset(ExecState*);
    5765int equivalentYearForDST(int year);
    58 double getCurrentUTCTime();
    59 double getCurrentUTCTimeWithMicroseconds();
    60 void getLocalTime(const time_t*, tm*);
    6166
    6267// Not really math related, but this is currently the only shared place to put these. 
    63 double parseDateFromNullTerminatedCharacters(const char*);
     68double parseDateFromNullTerminatedCharacters(const char* dateString, ExecState* exec); // exec may be 0
    6469double timeClip(double);
    6570
     
    99104    }
    100105
    101     GregorianDateTime(const tm& inTm)
     106    GregorianDateTime(ExecState* exec, const tm& inTm)
    102107        : second(inTm.tm_sec)
    103108        , minute(inTm.tm_min)
     
    110115        , isDST(inTm.tm_isdst)
    111116    {
     117        UNUSED_PARAM(exec);
    112118#if HAVE(TM_GMTOFF)
    113119        utcOffset = static_cast<int>(inTm.tm_gmtoff);
    114120#else
    115         utcOffset = static_cast<int>(getUTCOffset() / msPerSecond + (isDST ? secondsPerHour : 0));
     121        utcOffset = static_cast<int>(getUTCOffset(exec) / msPerSecond + (isDST ? secondsPerHour : 0));
    116122#endif
    117123
     
    188194}
    189195
    190 } // namespace WTF
     196} // namespace JSC
    191197
    192198#endif // DateMath_h
Note: See TracChangeset for help on using the changeset viewer.