source: webkit/trunk/JavaScriptCore/runtime/DateInstance.cpp@ 52075

Last change on this file since 52075 was 50708, checked in by [email protected], 16 years ago

Some manual inlining and constant propogation in Date code.

Reviewed by Sam Weinig.

SunSpider reports a 0.4% speedup on date-*, no overall speedup. Shark
says some previously evident stalls are now gone.

  • runtime/DateConstructor.cpp:

(JSC::callDate):

  • runtime/DateConversion.cpp:

(JSC::formatTime):
(JSC::formatTimeUTC): Split formatTime into UTC and non-UTC variants.

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

(JSC::DateInstance::calculateGregorianDateTime):
(JSC::DateInstance::calculateGregorianDateTimeUTC):

  • runtime/DateInstance.h:

(JSC::DateInstance::gregorianDateTime):
(JSC::DateInstance::gregorianDateTimeUTC): Split gregorianDateTime into
a UTC and non-UTC variant, and split each variant into a fast inline
case and a slow out-of-line case.

  • runtime/DatePrototype.cpp:

(JSC::formatLocaleDate):
(JSC::dateProtoFuncToString):
(JSC::dateProtoFuncToUTCString):
(JSC::dateProtoFuncToISOString):
(JSC::dateProtoFuncToDateString):
(JSC::dateProtoFuncToTimeString):
(JSC::dateProtoFuncGetFullYear):
(JSC::dateProtoFuncGetUTCFullYear):
(JSC::dateProtoFuncToGMTString):
(JSC::dateProtoFuncGetMonth):
(JSC::dateProtoFuncGetUTCMonth):
(JSC::dateProtoFuncGetDate):
(JSC::dateProtoFuncGetUTCDate):
(JSC::dateProtoFuncGetDay):
(JSC::dateProtoFuncGetUTCDay):
(JSC::dateProtoFuncGetHours):
(JSC::dateProtoFuncGetUTCHours):
(JSC::dateProtoFuncGetMinutes):
(JSC::dateProtoFuncGetUTCMinutes):
(JSC::dateProtoFuncGetSeconds):
(JSC::dateProtoFuncGetUTCSeconds):
(JSC::dateProtoFuncGetTimezoneOffset):
(JSC::setNewValueFromTimeArgs):
(JSC::setNewValueFromDateArgs):
(JSC::dateProtoFuncSetYear):
(JSC::dateProtoFuncGetYear): Updated for the gregorianDateTime change above.

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 *
20 */
21
22#include "config.h"
23#include "DateInstance.h"
24
25#include "JSGlobalObject.h"
26
27#include <math.h>
28#include <wtf/DateMath.h>
29#include <wtf/MathExtras.h>
30
31using namespace WTF;
32
33namespace JSC {
34
35const ClassInfo DateInstance::info = {"Date", 0, 0, 0};
36
37DateInstance::DateInstance(ExecState* exec, NonNullPassRefPtr<Structure> structure)
38 : JSWrapperObject(structure)
39{
40 setInternalValue(jsNaN(exec));
41}
42
43DateInstance::DateInstance(ExecState* exec, double time)
44 : JSWrapperObject(exec->lexicalGlobalObject()->dateStructure())
45{
46 setInternalValue(jsNumber(exec, timeClip(time)));
47}
48
49const GregorianDateTime* DateInstance::calculateGregorianDateTime(ExecState* exec) const
50{
51 double milli = internalNumber();
52 if (isnan(milli))
53 return 0;
54
55 if (!m_data)
56 m_data = exec->globalData().dateInstanceCache.add(milli);
57
58 if (m_data->m_gregorianDateTimeCachedForMS != milli) {
59 msToGregorianDateTime(exec, milli, false, m_data->m_cachedGregorianDateTime);
60 m_data->m_gregorianDateTimeCachedForMS = milli;
61 }
62 return &m_data->m_cachedGregorianDateTime;
63}
64
65const GregorianDateTime* DateInstance::calculateGregorianDateTimeUTC(ExecState* exec) const
66{
67 double milli = internalNumber();
68 if (isnan(milli))
69 return 0;
70
71 if (!m_data)
72 m_data = exec->globalData().dateInstanceCache.add(milli);
73
74 if (m_data->m_gregorianDateTimeUTCCachedForMS != milli) {
75 msToGregorianDateTime(exec, milli, true, m_data->m_cachedGregorianDateTimeUTC);
76 m_data->m_gregorianDateTimeUTCCachedForMS = milli;
77 }
78 return &m_data->m_cachedGregorianDateTimeUTC;
79}
80
81} // namespace JSC
Note: See TracBrowser for help on using the repository browser.