source: webkit/trunk/JavaScriptCore/kjs/DateInstance.cpp@ 37845

Last change on this file since 37845 was 36726, checked in by Darin Adler, 17 years ago

JavaScriptCore:

2008-09-20 Darin Adler <Darin Adler>

Reviewed by Maciej Stachowiak.

This also includes some optimizations that make the change an overall
small speedup. Without those it was a bit of a slowdown.

  • API/JSCallbackConstructor.cpp: (JSC::JSCallbackConstructor::JSCallbackConstructor): Take a structure.
  • API/JSCallbackConstructor.h: Ditto.
  • API/JSCallbackFunction.cpp: (JSC::JSCallbackFunction::JSCallbackFunction): Pass a structure.
  • API/JSCallbackObject.h: Take a structure.
  • API/JSCallbackObjectFunctions.h: (JSC::JSCallbackObject::JSCallbackObject): Ditto.
  • API/JSClassRef.cpp: (OpaqueJSClass::prototype): Pass in a structure. Call setPrototype if there's a custom prototype involved.
  • API/JSObjectRef.cpp: (JSObjectMake): Ditto. (JSObjectMakeConstructor): Pass in a structure.
  • VM/Machine.cpp: (JSC::jsLess): Added a special case for when both arguments are strings. This avoids converting both strings to with UString::toDouble. (JSC::jsLessEq): Ditto. (JSC::Machine::privateExecute): Pass in a structure. (JSC::Machine::cti_op_construct_JSConstruct): Ditto. (JSC::Machine::cti_op_new_regexp): Ditto. (JSC::Machine::cti_op_is_string): Ditto.
  • VM/Machine.h: Made isJSString public so it can be used in the CTI.
  • kjs/Arguments.cpp: (JSC::Arguments::Arguments): Pass in a structure.
  • kjs/JSCell.h: Mark constructor explicit.
  • kjs/JSGlobalObject.cpp: (JSC::markIfNeeded): Added an overload for marking structures. (JSC::JSGlobalObject::reset): Eliminate code to set data members to zero. We now do that in the constructor, and we no longer use this anywhere except in the constructor. Added code to create structures. Pass structures rather than prototypes when creating objects. (JSC::JSGlobalObject::mark): Mark the structures.
  • kjs/JSGlobalObject.h: Removed unneeded class declarations. Added initializers for raw pointers in JSGlobalObjectData so everything starts with a 0. Added structure data and accessor functions.
  • kjs/JSImmediate.cpp: (JSC::JSImmediate::nonInlineNaN): Added.
  • kjs/JSImmediate.h: (JSC::JSImmediate::toDouble): Rewrote to avoid PIC branches.
  • kjs/JSNumberCell.cpp: (JSC::jsNumberCell): Made non-inline to avoid PIC branches in functions that call this one. (JSC::jsNaN): Ditto.
  • kjs/JSNumberCell.h: Ditto.
  • kjs/JSObject.h: Removed constructor that takes a prototype. All callers now pass structures.
  • kjs/ArrayConstructor.cpp: (JSC::ArrayConstructor::ArrayConstructor): (JSC::constructArrayWithSizeQuirk):
  • kjs/ArrayConstructor.h:
  • kjs/ArrayPrototype.cpp: (JSC::ArrayPrototype::ArrayPrototype):
  • kjs/ArrayPrototype.h:
  • kjs/BooleanConstructor.cpp: (JSC::BooleanConstructor::BooleanConstructor): (JSC::constructBoolean): (JSC::constructBooleanFromImmediateBoolean):
  • kjs/BooleanConstructor.h:
  • kjs/BooleanObject.cpp: (JSC::BooleanObject::BooleanObject):
  • kjs/BooleanObject.h:
  • kjs/BooleanPrototype.cpp: (JSC::BooleanPrototype::BooleanPrototype):
  • kjs/BooleanPrototype.h:
  • kjs/DateConstructor.cpp: (JSC::DateConstructor::DateConstructor): (JSC::constructDate):
  • kjs/DateConstructor.h:
  • kjs/DateInstance.cpp: (JSC::DateInstance::DateInstance):
  • kjs/DateInstance.h:
  • kjs/DatePrototype.cpp: (JSC::DatePrototype::DatePrototype):
  • kjs/DatePrototype.h:
  • kjs/ErrorConstructor.cpp: (JSC::ErrorConstructor::ErrorConstructor): (JSC::constructError):
  • kjs/ErrorConstructor.h:
  • kjs/ErrorInstance.cpp: (JSC::ErrorInstance::ErrorInstance):
  • kjs/ErrorInstance.h:
  • kjs/ErrorPrototype.cpp: (JSC::ErrorPrototype::ErrorPrototype):
  • kjs/ErrorPrototype.h:
  • kjs/FunctionConstructor.cpp: (JSC::FunctionConstructor::FunctionConstructor):
  • kjs/FunctionConstructor.h:
  • kjs/FunctionPrototype.cpp: (JSC::FunctionPrototype::FunctionPrototype): (JSC::FunctionPrototype::addFunctionProperties):
  • kjs/FunctionPrototype.h:
  • kjs/GlobalEvalFunction.cpp: (JSC::GlobalEvalFunction::GlobalEvalFunction):
  • kjs/GlobalEvalFunction.h:
  • kjs/InternalFunction.cpp: (JSC::InternalFunction::InternalFunction):
  • kjs/InternalFunction.h: (JSC::InternalFunction::InternalFunction):
  • kjs/JSArray.cpp: (JSC::JSArray::JSArray): (JSC::constructEmptyArray): (JSC::constructArray):
  • kjs/JSArray.h:
  • kjs/JSFunction.cpp: (JSC::JSFunction::JSFunction): (JSC::JSFunction::construct):
  • kjs/JSObject.cpp: (JSC::constructEmptyObject):
  • kjs/JSString.cpp: (JSC::StringObject::create):
  • kjs/JSWrapperObject.h:
  • kjs/MathObject.cpp: (JSC::MathObject::MathObject):
  • kjs/MathObject.h:
  • kjs/NativeErrorConstructor.cpp: (JSC::NativeErrorConstructor::NativeErrorConstructor): (JSC::NativeErrorConstructor::construct):
  • kjs/NativeErrorConstructor.h:
  • kjs/NativeErrorPrototype.cpp: (JSC::NativeErrorPrototype::NativeErrorPrototype):
  • kjs/NativeErrorPrototype.h:
  • kjs/NumberConstructor.cpp: (JSC::NumberConstructor::NumberConstructor): (JSC::constructWithNumberConstructor):
  • kjs/NumberConstructor.h:
  • kjs/NumberObject.cpp: (JSC::NumberObject::NumberObject): (JSC::constructNumber): (JSC::constructNumberFromImmediateNumber):
  • kjs/NumberObject.h:
  • kjs/NumberPrototype.cpp: (JSC::NumberPrototype::NumberPrototype):
  • kjs/NumberPrototype.h:
  • kjs/ObjectConstructor.cpp: (JSC::ObjectConstructor::ObjectConstructor): (JSC::constructObject):
  • kjs/ObjectConstructor.h:
  • kjs/ObjectPrototype.cpp: (JSC::ObjectPrototype::ObjectPrototype):
  • kjs/ObjectPrototype.h:
  • kjs/PrototypeFunction.cpp: (JSC::PrototypeFunction::PrototypeFunction):
  • kjs/PrototypeFunction.h:
  • kjs/RegExpConstructor.cpp: (JSC::RegExpConstructor::RegExpConstructor): (JSC::RegExpMatchesArray::RegExpMatchesArray): (JSC::constructRegExp):
  • kjs/RegExpConstructor.h:
  • kjs/RegExpObject.cpp: (JSC::RegExpObject::RegExpObject):
  • kjs/RegExpObject.h:
  • kjs/RegExpPrototype.cpp: (JSC::RegExpPrototype::RegExpPrototype):
  • kjs/RegExpPrototype.h:
  • kjs/Shell.cpp: (GlobalObject::GlobalObject):
  • kjs/StringConstructor.cpp: (JSC::StringConstructor::StringConstructor): (JSC::constructWithStringConstructor):
  • kjs/StringConstructor.h:
  • kjs/StringObject.cpp: (JSC::StringObject::StringObject):
  • kjs/StringObject.h:
  • kjs/StringObjectThatMasqueradesAsUndefined.h: (JSC::StringObjectThatMasqueradesAsUndefined::StringObjectThatMasqueradesAsUndefined):
  • kjs/StringPrototype.cpp: (JSC::StringPrototype::StringPrototype):
  • kjs/StringPrototype.h: Take and pass structures.

WebCore:

2008-09-20 Darin Adler <Darin Adler>

Reviewed by Maciej Stachowiak.

  • bindings/js/JSCSSStyleDeclarationCustom.cpp: (WebCore::JSCSSStyleDeclaration::nameGetter): Pass in a structure ID. Note that this makes a new structure every time -- we could optimize this slightly be caching and reusing a single one.
  • bridge/runtime_method.cpp: (JSC::RuntimeMethod::RuntimeMethod): Create a unique structure using getDOMStructure.
  • bridge/runtime_method.h: (JSC::RuntimeMethod::createPrototype): Added createPrototype so getDOMStructure will work.
  • bindings/js/JSDOMWindowShell.cpp: (WebCore::JSDOMWindowShell::JSDOMWindowShell): Initialize m_window to 0; needed in case garbage collection happens while creating the JSDOMWindow.
  • Property svn:eol-style set to native
File size: 3.2 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 "DateMath.h"
26#include <math.h>
27#include <wtf/MathExtras.h>
28
29namespace JSC {
30
31struct DateInstance::Cache {
32 double m_gregorianDateTimeCachedForMS;
33 GregorianDateTime m_cachedGregorianDateTime;
34 double m_gregorianDateTimeUTCCachedForMS;
35 GregorianDateTime m_cachedGregorianDateTimeUTC;
36};
37
38const ClassInfo DateInstance::info = {"Date", 0, 0, 0};
39
40DateInstance::DateInstance(PassRefPtr<StructureID> structure)
41 : JSWrapperObject(structure)
42 , m_cache(0)
43{
44}
45
46DateInstance::~DateInstance()
47{
48 delete m_cache;
49}
50
51void DateInstance::msToGregorianDateTime(double milli, bool outputIsUTC, GregorianDateTime& t) const
52{
53 if (!m_cache) {
54 m_cache = new Cache;
55 m_cache->m_gregorianDateTimeCachedForMS = NaN;
56 m_cache->m_gregorianDateTimeUTCCachedForMS = NaN;
57 }
58
59 if (outputIsUTC) {
60 if (m_cache->m_gregorianDateTimeUTCCachedForMS != milli) {
61 JSC::msToGregorianDateTime(milli, true, m_cache->m_cachedGregorianDateTimeUTC);
62 m_cache->m_gregorianDateTimeUTCCachedForMS = milli;
63 }
64 t.copyFrom(m_cache->m_cachedGregorianDateTimeUTC);
65 } else {
66 if (m_cache->m_gregorianDateTimeCachedForMS != milli) {
67 JSC::msToGregorianDateTime(milli, false, m_cache->m_cachedGregorianDateTime);
68 m_cache->m_gregorianDateTimeCachedForMS = milli;
69 }
70 t.copyFrom(m_cache->m_cachedGregorianDateTime);
71 }
72}
73
74bool DateInstance::getTime(GregorianDateTime& t, int& offset) const
75{
76 double milli = internalNumber();
77 if (isnan(milli))
78 return false;
79
80 msToGregorianDateTime(milli, false, t);
81 offset = gmtoffset(t);
82 return true;
83}
84
85bool DateInstance::getUTCTime(GregorianDateTime& t) const
86{
87 double milli = internalNumber();
88 if (isnan(milli))
89 return false;
90
91 msToGregorianDateTime(milli, true, t);
92 return true;
93}
94
95bool DateInstance::getTime(double& milli, int& offset) const
96{
97 milli = internalNumber();
98 if (isnan(milli))
99 return false;
100
101 GregorianDateTime t;
102 msToGregorianDateTime(milli, false, t);
103 offset = gmtoffset(t);
104 return true;
105}
106
107bool DateInstance::getUTCTime(double& milli) const
108{
109 milli = internalNumber();
110 if (isnan(milli))
111 return false;
112
113 return true;
114}
115
116} // namespace JSC
Note: See TracBrowser for help on using the repository browser.