Changeset 50711 in webkit for trunk/JavaScriptCore


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

Imported the v8 DST cache.

Reviewed by Oliver Hunt.

SunSpider says 1.5% faster.

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::resetDateCache): Reset the DST cache when resetting
other date data.

  • runtime/JSGlobalData.h:

(JSC::DSTOffsetCache::DSTOffsetCache):
(JSC::DSTOffsetCache::reset): Added a struct for the DST cache.

  • wtf/DateMath.cpp:

(WTF::calculateDSTOffsetSimple):
(WTF::calculateDSTOffset):
(WTF::parseDateFromNullTerminatedCharacters):
(JSC::getDSTOffset):
(JSC::gregorianDateTimeToMS):
(JSC::msToGregorianDateTime):
(JSC::parseDateFromNullTerminatedCharacters):

  • wtf/DateMath.h: The imported code for probing and updating the cache.
Location:
trunk/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r50709 r50711  
     12009-11-09  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Imported the v8 DST cache.
     6       
     7        SunSpider says 1.5% faster.
     8
     9        * runtime/JSGlobalData.cpp:
     10        (JSC::JSGlobalData::resetDateCache): Reset the DST cache when resetting
     11        other date data.
     12
     13        * runtime/JSGlobalData.h:
     14        (JSC::DSTOffsetCache::DSTOffsetCache):
     15        (JSC::DSTOffsetCache::reset): Added a struct for the DST cache.
     16
     17        * wtf/DateMath.cpp:
     18        (WTF::calculateDSTOffsetSimple):
     19        (WTF::calculateDSTOffset):
     20        (WTF::parseDateFromNullTerminatedCharacters):
     21        (JSC::getDSTOffset):
     22        (JSC::gregorianDateTimeToMS):
     23        (JSC::msToGregorianDateTime):
     24        (JSC::parseDateFromNullTerminatedCharacters):
     25        * wtf/DateMath.h: The imported code for probing and updating the cache.
     26
    1272009-11-09  Geoffrey Garen  <[email protected]>
    228
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r50709 r50711  
    256256{
    257257    cachedUTCOffset = NaN;
     258    dstOffsetCache.reset();
    258259    cachedDateString = UString();
    259260    dateInstanceCache.reset();
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r50705 r50711  
    6363    struct Instruction;   
    6464    struct VPtrSet;
     65
     66    struct DSTOffsetCache {
     67        DSTOffsetCache()
     68        {
     69            reset();
     70        }
     71       
     72        void reset()
     73        {
     74            offset = 0.0;
     75            start = 0.0;
     76            end = -1.0;
     77            increment = 0.0;
     78        }
     79
     80        double offset;
     81        double start;
     82        double end;
     83        double increment;
     84    };
    6585
    6686    class JSGlobalData : public RefCounted<JSGlobalData> {
     
    155175
    156176        double cachedUTCOffset;
    157 
     177        DSTOffsetCache dstOffsetCache;
     178       
    158179        UString cachedDateString;
    159180        double cachedDateStringValue;
     
    173194        void createNativeThunk();
    174195    };
    175 
     196   
    176197} // namespace JSC
    177198
  • trunk/JavaScriptCore/wtf/DateMath.cpp

    r50705 r50711  
    4040 * If you do not delete the provisions above, a recipient may use your
    4141 * version of this file under any of the LGPL, the MPL or the GPL.
     42
     43 * Copyright 2006-2008 the V8 project authors. All rights reserved.
     44 * Redistribution and use in source and binary forms, with or without
     45 * modification, are permitted provided that the following conditions are
     46 * met:
     47 *
     48 *     * Redistributions of source code must retain the above copyright
     49 *       notice, this list of conditions and the following disclaimer.
     50 *     * Redistributions in binary form must reproduce the above
     51 *       copyright notice, this list of conditions and the following
     52 *       disclaimer in the documentation and/or other materials provided
     53 *       with the distribution.
     54 *     * Neither the name of Google Inc. nor the names of its
     55 *       contributors may be used to endorse or promote products derived
     56 *       from this software without specific prior written permission.
     57 *
     58 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     59 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     60 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     61 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     62 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     63 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     64 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     65 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     67 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     68 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    4269 */
    4370
     
    381408
    382409/*
    383  * Get the DST offset for the time passed in.  Takes
    384  * seconds (not milliseconds) and cannot handle dates before 1970
    385  * on some OS'
     410 * Get the DST offset for the time passed in.
    386411 */
    387 static double getDSTOffsetSimple(double localTimeSeconds, double utcOffset)
     412static double calculateDSTOffsetSimple(double localTimeSeconds, double utcOffset)
    388413{
    389414    if (localTimeSeconds > maxUnixTime)
     
    414439
    415440// Get the DST offset, given a time in UTC
    416 static double getDSTOffset(double ms, double utcOffset)
    417 {
    418     // On Mac OS X, the call to localtime (see getDSTOffsetSimple) will return historically accurate
     441static double calculateDSTOffset(double ms, double utcOffset)
     442{
     443    // On Mac OS X, the call to localtime (see calculateDSTOffsetSimple) will return historically accurate
    419444    // DST information (e.g. New Zealand did not have DST from 1946 to 1974) however the JavaScript
    420445    // standard explicitly dictates that historical information should not be considered when
     
    432457    }
    433458
    434     return getDSTOffsetSimple(ms / msPerSecond, utcOffset);
     459    return calculateDSTOffsetSimple(ms / msPerSecond, utcOffset);
    435460}
    436461
     
    803828    if (!haveTZ) {
    804829        double utcOffset = calculateUTCOffset();
    805         double dstOffset = getDSTOffset(ms, utcOffset);
     830        double dstOffset = calculateDSTOffset(ms, utcOffset);
    806831        offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute);
    807832    }
     
    821846#if USE(JSC)
    822847namespace JSC {
     848
     849// Get the DST offset for the time passed in.
     850//
     851// NOTE: The implementation relies on the fact that no time zones have
     852// more than one daylight savings offset change per month.
     853// If this function is called with NaN it returns NaN.
     854static double getDSTOffset(ExecState* exec, double ms, double utcOffset)
     855{
     856    DSTOffsetCache& cache = exec->globalData().dstOffsetCache;
     857    double start = cache.start;
     858    double end = cache.end;
     859
     860    if (start <= ms) {
     861        // If the time fits in the cached interval, return the cached offset.
     862        if (ms <= end) return cache.offset;
     863
     864        // Compute a possible new interval end.
     865        double newEnd = end + cache.increment;
     866
     867        if (ms <= newEnd) {
     868            double endOffset = calculateDSTOffset(newEnd, utcOffset);
     869            if (cache.offset == endOffset) {
     870                // If the offset at the end of the new interval still matches
     871                // the offset in the cache, we grow the cached time interval
     872                // and return the offset.
     873                cache.end = newEnd;
     874                cache.increment = msPerMonth;
     875                return endOffset;
     876            } else {
     877                double offset = calculateDSTOffset(ms, utcOffset);
     878                if (offset == endOffset) {
     879                    // The offset at the given time is equal to the offset at the
     880                    // new end of the interval, so that means that we've just skipped
     881                    // the point in time where the DST offset change occurred. Updated
     882                    // the interval to reflect this and reset the increment.
     883                    cache.start = ms;
     884                    cache.end = newEnd;
     885                    cache.increment = msPerMonth;
     886                } else {
     887                    // The interval contains a DST offset change and the given time is
     888                    // before it. Adjust the increment to avoid a linear search for
     889                    // the offset change point and change the end of the interval.
     890                    cache.increment /= 3;
     891                    cache.end = ms;
     892                }
     893                // Update the offset in the cache and return it.
     894                cache.offset = offset;
     895                return offset;
     896            }
     897        }
     898    }
     899
     900    // Compute the DST offset for the time and shrink the cache interval
     901    // to only contain the time. This allows fast repeated DST offset
     902    // computations for the same time.
     903    double offset = calculateDSTOffset(ms, utcOffset);
     904    cache.offset = offset;
     905    cache.start = ms;
     906    cache.end = ms;
     907    cache.increment = msPerMonth;
     908    return offset;
     909}
     910
    823911/*
    824912 * Get the difference in milliseconds between this time zone and UTC (GMT)
     
    843931        double utcOffset = getUTCOffset(exec);
    844932        result -= utcOffset;
    845         result -= getDSTOffset(result, utcOffset);
     933        result -= getDSTOffset(exec, result, utcOffset);
    846934    }
    847935
     
    856944    if (!outputIsUTC) {
    857945        utcOff = getUTCOffset(exec);
    858         dstOff = getDSTOffset(ms, utcOff);
     946        dstOff = getDSTOffset(exec, ms, utcOff);
    859947        ms += dstOff + utcOff;
    860948    }
     
    883971    if (!haveTZ) {
    884972        double utcOffset = getUTCOffset(exec);
    885         double dstOffset = getDSTOffset(ms, utcOffset);
     973        double dstOffset = getDSTOffset(exec, ms, utcOffset);
    886974        offset = static_cast<int>((utcOffset + dstOffset) / WTF::msPerMinute);
    887975    }
  • trunk/JavaScriptCore/wtf/DateMath.h

    r50705 r50711  
    7575const double msPerHour = 60.0 * 60.0 * 1000.0;
    7676const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;
     77const double msPerMonth = 2592000000.0;
    7778
    7879} // namespace WTF
Note: See TracChangeset for help on using the changeset viewer.