Changeset 50174 in webkit for trunk/JavaScriptCore
- Timestamp:
- Oct 27, 2009, 3:01:41 PM (16 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r50173 r50174 1 2009-10-27 Geoffrey Garen <[email protected]> 2 3 Reviewed by Darin Adler and Oliver Hunt. 4 5 https://bugs.webkit.org/show_bug.cgi?id=30800 6 Cache recently computed date data. 7 8 SunSpider reports a ~0.5% speedup, mostly from date-format-tofte.js. 9 10 * GNUmakefile.am: 11 * JavaScriptCore.gypi: 12 * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: 13 * JavaScriptCore.xcodeproj/project.pbxproj: Added new file. 14 15 * runtime/DateInstance.cpp: 16 (JSC::DateInstance::DateInstance): 17 (JSC::DateInstance::getGregorianDateTime): Use the shared cache. 18 19 * runtime/DateInstance.h: Renamed m_cache to m_data, to avoid the confusion 20 of a "cache cache". 21 22 * runtime/DatePrototype.cpp: 23 (JSC::formatLocaleDate): 24 (JSC::dateProtoFuncToString): 25 (JSC::dateProtoFuncToUTCString): 26 (JSC::dateProtoFuncToISOString): 27 (JSC::dateProtoFuncToDateString): 28 (JSC::dateProtoFuncToTimeString): 29 (JSC::dateProtoFuncGetFullYear): 30 (JSC::dateProtoFuncGetUTCFullYear): 31 (JSC::dateProtoFuncToGMTString): 32 (JSC::dateProtoFuncGetMonth): 33 (JSC::dateProtoFuncGetUTCMonth): 34 (JSC::dateProtoFuncGetDate): 35 (JSC::dateProtoFuncGetUTCDate): 36 (JSC::dateProtoFuncGetDay): 37 (JSC::dateProtoFuncGetUTCDay): 38 (JSC::dateProtoFuncGetHours): 39 (JSC::dateProtoFuncGetUTCHours): 40 (JSC::dateProtoFuncGetMinutes): 41 (JSC::dateProtoFuncGetUTCMinutes): 42 (JSC::dateProtoFuncGetSeconds): 43 (JSC::dateProtoFuncGetUTCSeconds): 44 (JSC::dateProtoFuncGetTimezoneOffset): 45 (JSC::setNewValueFromTimeArgs): 46 (JSC::setNewValueFromDateArgs): 47 (JSC::dateProtoFuncSetYear): 48 (JSC::dateProtoFuncGetYear): Pass an ExecState to these functions, so they 49 can access the DateInstanceCache. 50 51 * runtime/JSGlobalData.h: Keep a DateInstanceCache. 52 1 53 2009-10-27 James Robinson <[email protected]> 2 54 -
trunk/JavaScriptCore/GNUmakefile.am
r49802 r50174 391 391 JavaScriptCore/runtime/DateInstance.cpp \ 392 392 JavaScriptCore/runtime/DateInstance.h \ 393 JavaScriptCore/runtime/DateInstanceCache.h \ 393 394 JavaScriptCore/runtime/DatePrototype.cpp \ 394 395 JavaScriptCore/runtime/DatePrototype.h \ -
trunk/JavaScriptCore/JavaScriptCore.gypi
r49802 r50174 195 195 'runtime/DateInstance.cpp', 196 196 'runtime/DateInstance.h', 197 'runtime/DateInstanceCache.h', 197 198 'runtime/DatePrototype.cpp', 198 199 'runtime/DatePrototype.h', -
trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
r49802 r50174 663 663 <File 664 664 RelativePath="..\..\runtime\DateInstance.h" 665 > 666 </File> 667 <File 668 RelativePath="..\..\runtime\DateInstanceCache.h" 665 669 > 666 670 </File> -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r49802 r50174 158 158 148F21BC107EC54D0042EC2C /* Parser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F0B3A909BB4DC00068FCE3 /* Parser.cpp */; }; 159 159 149559EE0DDCDDF700648087 /* DebuggerCallFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 149559ED0DDCDDF700648087 /* DebuggerCallFrame.cpp */; }; 160 14A1563210966365006FA260 /* DateInstanceCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 14A1563010966365006FA260 /* DateInstanceCache.h */; }; 160 161 14A23D750F4E1ABB0023CDAD /* JITStubs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14A23D6C0F4E19CE0023CDAD /* JITStubs.cpp */; }; 161 162 14A42E3F0F4F60EE00599099 /* TimeoutChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14A42E3D0F4F60EE00599099 /* TimeoutChecker.cpp */; }; … … 616 617 149559ED0DDCDDF700648087 /* DebuggerCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DebuggerCallFrame.cpp; sourceTree = "<group>"; }; 617 618 149B24FF0D8AF6D1009CB8C7 /* Register.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Register.h; sourceTree = "<group>"; }; 619 14A1563010966365006FA260 /* DateInstanceCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DateInstanceCache.h; sourceTree = "<group>"; }; 618 620 14A23D6C0F4E19CE0023CDAD /* JITStubs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITStubs.cpp; sourceTree = "<group>"; }; 619 621 14A396A60CD2933100B5B4FF /* SymbolTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SymbolTable.h; sourceTree = "<group>"; }; … … 1417 1419 isa = PBXGroup; 1418 1420 children = ( 1419 A7FB604B103F5EAB0017A286 /* PropertyDescriptor.h */,1420 1421 BCF605110E203EF800B9A64D /* ArgList.cpp */, 1421 1422 BCF605120E203EF800B9A64D /* ArgList.h */, … … 1451 1452 BC1166000E1997B1008066DD /* DateInstance.cpp */, 1452 1453 BC1166010E1997B1008066DD /* DateInstance.h */, 1454 14A1563010966365006FA260 /* DateInstanceCache.h */, 1453 1455 BCD203470E17135E002C7E82 /* DatePrototype.cpp */, 1454 1456 BCD203480E17135E002C7E82 /* DatePrototype.h */, … … 1514 1516 F692A8620255597D01FF60F7 /* JSString.h */, 1515 1517 14ABB454099C2A0F00E2A24F /* JSType.h */, 1518 6507D2970E871E4A00D7D896 /* JSTypeInfo.h */, 1516 1519 F692A8870255597D01FF60F7 /* JSValue.cpp */, 1517 1520 14ABB36E099C076400E2A24F /* JSValue.h */, … … 1524 1527 F692A8680255597D01FF60F7 /* Lookup.cpp */, 1525 1528 F692A8690255597D01FF60F7 /* Lookup.h */, 1529 A74B3498102A5F8E0032AB98 /* MarkStack.cpp */, 1530 A779558F101A74D500114E55 /* MarkStack.h */, 1531 A7C530E3102A3813005BC741 /* MarkStackPosix.cpp */, 1526 1532 F692A86A0255597D01FF60F7 /* MathObject.cpp */, 1527 1533 F692A86B0255597D01FF60F7 /* MathObject.h */, … … 1544 1550 F692A8770255597D01FF60F7 /* Operations.cpp */, 1545 1551 F692A8780255597D01FF60F7 /* Operations.h */, 1552 A7FB60A3103F7DC20017A286 /* PropertyDescriptor.cpp */, 1553 A7FB604B103F5EAB0017A286 /* PropertyDescriptor.h */, 1546 1554 BC95437C0EBA70FD0072B6D3 /* PropertyMapHashTable.h */, 1547 1555 65400C0F0A69BAF200509887 /* PropertyNameArray.cpp */, … … 1584 1592 5D53726D0E1C546B0021E549 /* Tracing.d */, 1585 1593 5D53726E0E1C54880021E549 /* Tracing.h */, 1586 6507D2970E871E4A00D7D896 /* JSTypeInfo.h */,1587 1594 F692A8850255597D01FF60F7 /* UString.cpp */, 1588 1595 F692A8860255597D01FF60F7 /* UString.h */, 1589 A779558F101A74D500114E55 /* MarkStack.h */,1590 A7C530E3102A3813005BC741 /* MarkStackPosix.cpp */,1591 A74B3498102A5F8E0032AB98 /* MarkStack.cpp */,1592 A7FB60A3103F7DC20017A286 /* PropertyDescriptor.cpp */,1593 1596 ); 1594 1597 path = runtime; … … 1999 2002 BC87CDB910712AD4000614CF /* JSONObject.lut.h in Headers */, 2000 2003 148CD1D8108CF902008163C6 /* JSContextRefPrivate.h in Headers */, 2004 14A1563210966365006FA260 /* DateInstanceCache.h in Headers */, 2001 2005 ); 2002 2006 runOnlyForDeploymentPostprocessing = 0; -
trunk/JavaScriptCore/runtime/DateInstance.cpp
r49886 r50174 33 33 namespace JSC { 34 34 35 struct DateInstance::Cache {36 double m_gregorianDateTimeCachedForMS;37 GregorianDateTime m_cachedGregorianDateTime;38 double m_gregorianDateTimeUTCCachedForMS;39 GregorianDateTime m_cachedGregorianDateTimeUTC;40 };41 42 35 const ClassInfo DateInstance::info = {"Date", 0, 0, 0}; 43 36 44 37 DateInstance::DateInstance(NonNullPassRefPtr<Structure> structure) 45 38 : JSWrapperObject(structure) 46 , m_cache(0)47 39 { 48 40 } … … 50 42 DateInstance::DateInstance(ExecState* exec, double time) 51 43 : JSWrapperObject(exec->lexicalGlobalObject()->dateStructure()) 52 , m_cache(0)53 44 { 54 45 setInternalValue(jsNumber(exec, timeClip(time))); 55 46 } 56 47 57 DateInstance::~DateInstance() 48 bool DateInstance::getGregorianDateTime(ExecState* exec, bool outputIsUTC, GregorianDateTime& t) const 58 49 { 59 delete m_cache;60 }61 62 bool DateInstance::getGregorianDateTime(bool outputIsUTC, GregorianDateTime& t) const63 {64 if (!m_cache) {65 m_cache = new Cache;66 m_cache->m_gregorianDateTimeCachedForMS = NaN;67 m_cache->m_gregorianDateTimeUTCCachedForMS = NaN;68 }69 70 50 double milli = internalNumber(); 71 51 if (isnan(milli)) 72 52 return false; 73 53 54 if (!m_data) 55 m_data = exec->globalData().dateInstanceCache.add(milli); 56 74 57 if (outputIsUTC) { 75 if (m_ cache->m_gregorianDateTimeUTCCachedForMS != milli) {76 WTF::msToGregorianDateTime(internalNumber(), true, m_ cache->m_cachedGregorianDateTimeUTC);77 m_ cache->m_gregorianDateTimeUTCCachedForMS = milli;58 if (m_data->m_gregorianDateTimeUTCCachedForMS != milli) { 59 WTF::msToGregorianDateTime(internalNumber(), true, m_data->m_cachedGregorianDateTimeUTC); 60 m_data->m_gregorianDateTimeUTCCachedForMS = milli; 78 61 } 79 t.copyFrom(m_ cache->m_cachedGregorianDateTimeUTC);62 t.copyFrom(m_data->m_cachedGregorianDateTimeUTC); 80 63 } else { 81 if (m_ cache->m_gregorianDateTimeCachedForMS != milli) {82 WTF::msToGregorianDateTime(internalNumber(), false, m_ cache->m_cachedGregorianDateTime);83 m_ cache->m_gregorianDateTimeCachedForMS = milli;64 if (m_data->m_gregorianDateTimeCachedForMS != milli) { 65 WTF::msToGregorianDateTime(internalNumber(), false, m_data->m_cachedGregorianDateTime); 66 m_data->m_gregorianDateTimeCachedForMS = milli; 84 67 } 85 t.copyFrom(m_ cache->m_cachedGregorianDateTime);68 t.copyFrom(m_data->m_cachedGregorianDateTime); 86 69 } 87 70 88 71 return true; 89 72 } -
trunk/JavaScriptCore/runtime/DateInstance.h
r49886 r50174 34 34 DateInstance(ExecState*, double); 35 35 explicit DateInstance(NonNullPassRefPtr<Structure>); 36 virtual ~DateInstance();37 36 38 37 double internalNumber() const { return internalValue().uncheckedGetNumber(); } … … 45 44 static JS_EXPORTDATA const ClassInfo info; 46 45 47 bool getGregorianDateTime( bool outputIsUTC, WTF::GregorianDateTime&) const;46 bool getGregorianDateTime(ExecState*, bool outputIsUTC, WTF::GregorianDateTime&) const; 48 47 49 48 static PassRefPtr<Structure> createStructure(JSValue prototype) … … 58 57 virtual const ClassInfo* classInfo() const { return &info; } 59 58 60 61 struct Cache; 62 mutable Cache* m_cache; 59 mutable RefPtr<DateInstanceData> m_data; 63 60 }; 64 61 -
trunk/JavaScriptCore/runtime/DatePrototype.cpp
r49889 r50174 256 256 GregorianDateTime gregorianDateTime; 257 257 const bool outputIsUTC = false; 258 if (!dateObject->getGregorianDateTime( outputIsUTC, gregorianDateTime))258 if (!dateObject->getGregorianDateTime(exec, outputIsUTC, gregorianDateTime)) 259 259 return jsNontrivialString(exec, "Invalid Date"); 260 260 return formatLocaleDate(exec, gregorianDateTime, format); … … 427 427 428 428 GregorianDateTime t; 429 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))429 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 430 430 return jsNontrivialString(exec, "Invalid Date"); 431 431 return jsNontrivialString(exec, formatDate(t) + " " + formatTime(t, outputIsUTC)); … … 442 442 443 443 GregorianDateTime t; 444 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))444 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 445 445 return jsNontrivialString(exec, "Invalid Date"); 446 446 return jsNontrivialString(exec, formatDateUTCVariant(t) + " " + formatTime(t, outputIsUTC)); … … 457 457 458 458 GregorianDateTime t; 459 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))459 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 460 460 return jsNontrivialString(exec, "Invalid Date"); 461 461 // Maximum amount of space we need in buffer: 6 (max. digits in year) + 2 * 5 (2 characters each for month, day, hour, minute, second) + 4 (. + 3 digits for milliseconds) … … 477 477 478 478 GregorianDateTime t; 479 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))479 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 480 480 return jsNontrivialString(exec, "Invalid Date"); 481 481 return jsNontrivialString(exec, formatDate(t)); … … 492 492 493 493 GregorianDateTime t; 494 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))494 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 495 495 return jsNontrivialString(exec, "Invalid Date"); 496 496 return jsNontrivialString(exec, formatTime(t, outputIsUTC)); … … 542 542 543 543 GregorianDateTime t; 544 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))544 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 545 545 return jsNaN(exec); 546 546 return jsNumber(exec, 1900 + t.year); … … 557 557 558 558 GregorianDateTime t; 559 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))559 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 560 560 return jsNaN(exec); 561 561 return jsNumber(exec, 1900 + t.year); … … 572 572 573 573 GregorianDateTime t; 574 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))574 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 575 575 return jsNontrivialString(exec, "Invalid Date"); 576 576 return jsNontrivialString(exec, formatDateUTCVariant(t) + " " + formatTime(t, outputIsUTC)); … … 587 587 588 588 GregorianDateTime t; 589 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))589 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 590 590 return jsNaN(exec); 591 591 return jsNumber(exec, t.month); … … 602 602 603 603 GregorianDateTime t; 604 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))604 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 605 605 return jsNaN(exec); 606 606 return jsNumber(exec, t.month); … … 617 617 618 618 GregorianDateTime t; 619 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))619 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 620 620 return jsNaN(exec); 621 621 return jsNumber(exec, t.monthDay); … … 632 632 633 633 GregorianDateTime t; 634 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))634 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 635 635 return jsNaN(exec); 636 636 return jsNumber(exec, t.monthDay); … … 647 647 648 648 GregorianDateTime t; 649 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))649 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 650 650 return jsNaN(exec); 651 651 return jsNumber(exec, t.weekDay); … … 662 662 663 663 GregorianDateTime t; 664 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))664 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 665 665 return jsNaN(exec); 666 666 return jsNumber(exec, t.weekDay); … … 677 677 678 678 GregorianDateTime t; 679 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))679 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 680 680 return jsNaN(exec); 681 681 return jsNumber(exec, t.hour); … … 692 692 693 693 GregorianDateTime t; 694 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))694 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 695 695 return jsNaN(exec); 696 696 return jsNumber(exec, t.hour); … … 707 707 708 708 GregorianDateTime t; 709 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))709 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 710 710 return jsNaN(exec); 711 711 return jsNumber(exec, t.minute); … … 722 722 723 723 GregorianDateTime t; 724 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))724 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 725 725 return jsNaN(exec); 726 726 return jsNumber(exec, t.minute); … … 737 737 738 738 GregorianDateTime t; 739 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))739 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 740 740 return jsNaN(exec); 741 741 return jsNumber(exec, t.second); … … 752 752 753 753 GregorianDateTime t; 754 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))754 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 755 755 return jsNaN(exec); 756 756 return jsNumber(exec, t.second); … … 797 797 798 798 GregorianDateTime t; 799 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))799 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 800 800 return jsNaN(exec); 801 801 return jsNumber(exec, -gmtoffset(t) / minutesPerHour); … … 833 833 834 834 GregorianDateTime t; 835 thisDateObj->getGregorianDateTime( inputIsUTC, t);835 thisDateObj->getGregorianDateTime(exec, inputIsUTC, t); 836 836 837 837 if (!fillStructuresUsingTimeArgs(exec, args, numArgsToUse, &ms, &t)) { … … 869 869 double secs = floor(milli / msPerSecond); 870 870 ms = milli - secs * msPerSecond; 871 thisDateObj->getGregorianDateTime( inputIsUTC, t);871 thisDateObj->getGregorianDateTime(exec, inputIsUTC, t); 872 872 } 873 873 … … 992 992 double secs = floor(milli / msPerSecond); 993 993 ms = milli - secs * msPerSecond; 994 thisDateObj->getGregorianDateTime( outputIsUTC, t);994 thisDateObj->getGregorianDateTime(exec, outputIsUTC, t); 995 995 } 996 996 … … 1019 1019 1020 1020 GregorianDateTime t; 1021 if (!thisDateObj->getGregorianDateTime( outputIsUTC, t))1021 if (!thisDateObj->getGregorianDateTime(exec, outputIsUTC, t)) 1022 1022 return jsNaN(exec); 1023 1023 -
trunk/JavaScriptCore/runtime/JSGlobalData.h
r49328 r50174 31 31 32 32 #include "Collector.h" 33 #include "DateInstanceCache.h" 33 34 #include "ExecutableAllocator.h" 34 35 #include "JITStubs.h" … … 117 118 SmallStrings smallStrings; 118 119 NumericStrings numericStrings; 119 120 DateInstanceCache dateInstanceCache; 121 120 122 #if ENABLE(ASSEMBLER) 121 123 ExecutableAllocator executableAllocator;
Note:
See TracChangeset
for help on using the changeset viewer.