Title: [254899] trunk/Source
Revision
254899
Author
[email protected]
Date
2020-01-21 19:11:39 -0800 (Tue, 21 Jan 2020)

Log Message

[JSC] Date parse logic should be less redundant
https://bugs.webkit.org/show_bug.cgi?id=206560

Reviewed by Darin Adler.

Source/_javascript_Core:

Our date parsing logic is doing an excessive amount of NaN-checking;
let's streamline this by having one JSC-side helper function instead of two.

* runtime/JSDateMath.cpp:
(JSC::parseDate):
(JSC::parseDateFromNullTerminatedCharacters): Deleted.
(JSC::parseES5DateFromNullTerminatedCharacters): Deleted.

Source/WTF:

* wtf/DateMath.cpp:
(WTF::parseDateFromNullTerminatedCharacters):
* wtf/DateMath.h:
Align function signature with parseES5DateFromNullTerminatedCharacters.
Namely, drop the integer out param and flip the boolean one.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (254898 => 254899)


--- trunk/Source/_javascript_Core/ChangeLog	2020-01-22 01:59:34 UTC (rev 254898)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-01-22 03:11:39 UTC (rev 254899)
@@ -1,3 +1,18 @@
+2020-01-21  Ross Kirsling  <[email protected]>
+
+        [JSC] Date parse logic should be less redundant
+        https://bugs.webkit.org/show_bug.cgi?id=206560
+
+        Reviewed by Darin Adler.
+
+        Our date parsing logic is doing an excessive amount of NaN-checking;
+        let's streamline this by having one JSC-side helper function instead of two.
+
+        * runtime/JSDateMath.cpp:
+        (JSC::parseDate):
+        (JSC::parseDateFromNullTerminatedCharacters): Deleted.
+        (JSC::parseES5DateFromNullTerminatedCharacters): Deleted.
+
 2020-01-21  Rob Buis  <[email protected]>
 
         Add build flag for stale-while-revalidate

Modified: trunk/Source/_javascript_Core/runtime/JSDateMath.cpp (254898 => 254899)


--- trunk/Source/_javascript_Core/runtime/JSDateMath.cpp	2020-01-22 01:59:34 UTC (rev 254898)
+++ trunk/Source/_javascript_Core/runtime/JSDateMath.cpp	2020-01-22 03:11:39 UTC (rev 254899)
@@ -192,27 +192,12 @@
     tm = GregorianDateTime(ms, localTime);
 }
 
-static double parseDateFromNullTerminatedCharacters(VM& vm, const char* dateString)
+static double parseDate(VM& vm, const char* dateString)
 {
-    bool haveTZ;
-    int offset;
-    double localTimeMS = WTF::parseDateFromNullTerminatedCharacters(dateString, haveTZ, offset);
-    if (std::isnan(localTimeMS))
-        return std::numeric_limits<double>::quiet_NaN();
-
-    // fall back to local timezone.
-    if (!haveTZ)
-        offset = localTimeOffset(vm, localTimeMS, WTF::LocalTime).offset / WTF::msPerMinute;
-
-    return localTimeMS - (offset * WTF::msPerMinute);
-}
-
-static double parseES5DateFromNullTerminatedCharacters(VM& vm, const char* dateString)
-{
     bool isLocalTime;
     double value = WTF::parseES5DateFromNullTerminatedCharacters(dateString, isLocalTime);
     if (std::isnan(value))
-        return std::numeric_limits<double>::quiet_NaN();
+        value = WTF::parseDateFromNullTerminatedCharacters(dateString, isLocalTime);
 
     if (isLocalTime)
         value -= localTimeOffset(vm, value, WTF::LocalTime).offset;
@@ -237,9 +222,7 @@
     }
 
     auto dateUtf8 = expectedString.value();
-    double value = parseES5DateFromNullTerminatedCharacters(vm, dateUtf8.data());
-    if (std::isnan(value))
-        value = parseDateFromNullTerminatedCharacters(vm, dateUtf8.data());
+    double value = parseDate(vm, dateUtf8.data());
     vm.cachedDateString = date;
     vm.cachedDateStringValue = value;
     return value;

Modified: trunk/Source/WTF/ChangeLog (254898 => 254899)


--- trunk/Source/WTF/ChangeLog	2020-01-22 01:59:34 UTC (rev 254898)
+++ trunk/Source/WTF/ChangeLog	2020-01-22 03:11:39 UTC (rev 254899)
@@ -1,3 +1,16 @@
+2020-01-21  Ross Kirsling  <[email protected]>
+
+        [JSC] Date parse logic should be less redundant
+        https://bugs.webkit.org/show_bug.cgi?id=206560
+
+        Reviewed by Darin Adler.
+
+        * wtf/DateMath.cpp:
+        (WTF::parseDateFromNullTerminatedCharacters):
+        * wtf/DateMath.h:
+        Align function signature with parseES5DateFromNullTerminatedCharacters.
+        Namely, drop the integer out param and flip the boolean one.
+
 2020-01-21  Yusuke Suzuki  <[email protected]>
 
         [WTF] AtomStringTable should be small

Modified: trunk/Source/WTF/wtf/DateMath.cpp (254898 => 254899)


--- trunk/Source/WTF/wtf/DateMath.cpp	2020-01-22 01:59:34 UTC (rev 254898)
+++ trunk/Source/WTF/wtf/DateMath.cpp	2020-01-22 03:11:39 UTC (rev 254899)
@@ -682,10 +682,10 @@
 }
 
 // Odd case where 'exec' is allowed to be 0, to accomodate a caller in WebCore.
-double parseDateFromNullTerminatedCharacters(const char* dateString, bool& haveTZ, int& offset)
+double parseDateFromNullTerminatedCharacters(const char* dateString, bool& isLocalTime)
 {
-    haveTZ = false;
-    offset = 0;
+    isLocalTime = true;
+    int offset = 0;
 
     // This parses a date in the form:
     //     Tuesday, 09-Nov-99 23:12:40 GMT
@@ -903,7 +903,7 @@
     if (*dateString) {
         if (startsWithLettersIgnoringASCIICase(dateString, "gmt") || startsWithLettersIgnoringASCIICase(dateString, "utc")) {
             dateString += 3;
-            haveTZ = true;
+            isLocalTime = false;
         }
 
         if (*dateString == '+' || *dateString == '-') {
@@ -930,7 +930,7 @@
                 dateString = newPosStr;
                 offset = (o * 60 + o2) * sgn;
             }
-            haveTZ = true;
+            isLocalTime = false;
         } else {
             for (auto& knownZone : knownZones) {
                 // Since the passed-in length is used for both strings, the following checks that
@@ -939,7 +939,7 @@
                 if (equalLettersIgnoringASCIICase(dateString, knownZone.tzName, length)) {
                     offset = knownZone.tzOffset;
                     dateString += length;
-                    haveTZ = true;
+                    isLocalTime = false;
                     break;
                 }
             }
@@ -982,23 +982,20 @@
         year = 2000;
     }
     ASSERT(year);
-    
-    return ymdhmsToSeconds(year.value(), month + 1, day, hour, minute, second) * msPerSecond;
+
+    double dateSeconds = ymdhmsToSeconds(year.value(), month + 1, day, hour, minute, second) - offset * secondsPerMinute;
+    return dateSeconds * msPerSecond;
 }
 
 double parseDateFromNullTerminatedCharacters(const char* dateString)
 {
-    bool haveTZ;
-    int offset;
-    double ms = parseDateFromNullTerminatedCharacters(dateString, haveTZ, offset);
-    if (std::isnan(ms))
-        return std::numeric_limits<double>::quiet_NaN();
+    bool isLocalTime;
+    double value = parseDateFromNullTerminatedCharacters(dateString, isLocalTime);
 
-    // fall back to local timezone
-    if (!haveTZ)
-        offset = calculateLocalTimeOffset(ms, LocalTime).offset / msPerMinute; // ms value is in local time milliseconds.
+    if (isLocalTime)
+        value -= calculateLocalTimeOffset(value, LocalTime).offset;
 
-    return ms - (offset * msPerMinute);
+    return value;
 }
 
 // See http://tools.ietf.org/html/rfc2822#section-3.3 for more information.

Modified: trunk/Source/WTF/wtf/DateMath.h (254898 => 254899)


--- trunk/Source/WTF/wtf/DateMath.h	2020-01-22 01:59:34 UTC (rev 254898)
+++ trunk/Source/WTF/wtf/DateMath.h	2020-01-22 03:11:39 UTC (rev 254899)
@@ -91,7 +91,7 @@
 // Not really math related, but this is currently the only shared place to put these.
 WTF_EXPORT_PRIVATE double parseES5DateFromNullTerminatedCharacters(const char* dateString, bool& isLocalTime);
 WTF_EXPORT_PRIVATE double parseDateFromNullTerminatedCharacters(const char* dateString);
-WTF_EXPORT_PRIVATE double parseDateFromNullTerminatedCharacters(const char* dateString, bool& haveTZ, int& offset);
+WTF_EXPORT_PRIVATE double parseDateFromNullTerminatedCharacters(const char* dateString, bool& isLocalTime);
 // dayOfWeek: [0, 6] 0 being Monday, day: [1, 31], month: [0, 11], year: ex: 2011, hours: [0, 23], minutes: [0, 59], seconds: [0, 59], utcOffset: [-720,720]. 
 String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned minutes, unsigned seconds, int utcOffset);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to