Title: [194578] trunk/Source/WebCore
Revision
194578
Author
[email protected]
Date
2016-01-04 23:46:14 -0800 (Mon, 04 Jan 2016)

Log Message

[PerformanceTiming] Don't expose the restrictedKeyMap() HashMap
https://bugs.webkit.org/show_bug.cgi?id=147366

Reviewed by Sam Weinig.

Instead of the callers looking up in the HashMap that's returned by restrictedKeyMap(),
keep the HashMap local in the static restrictedMarkFunction(). This function accepts
a String reference and performs the lookup, returning the pointer to a PerformanceTiming
method that corresponds to the passed-in mark or returns nullptr otherwise.

The HashMap is now wrapped in a NeverDestroyed object and is populated when the first
mark function is looked for.

* page/PerformanceUserTiming.cpp:
(WebCore::UserTiming::mark):
(WebCore::UserTiming::findExistingMarkStartTime):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (194577 => 194578)


--- trunk/Source/WebCore/ChangeLog	2016-01-05 07:41:39 UTC (rev 194577)
+++ trunk/Source/WebCore/ChangeLog	2016-01-05 07:46:14 UTC (rev 194578)
@@ -1,5 +1,24 @@
 2016-01-04  Zan Dobersek  <[email protected]>
 
+        [PerformanceTiming] Don't expose the restrictedKeyMap() HashMap
+        https://bugs.webkit.org/show_bug.cgi?id=147366
+
+        Reviewed by Sam Weinig.
+
+        Instead of the callers looking up in the HashMap that's returned by restrictedKeyMap(),
+        keep the HashMap local in the static restrictedMarkFunction(). This function accepts
+        a String reference and performs the lookup, returning the pointer to a PerformanceTiming
+        method that corresponds to the passed-in mark or returns nullptr otherwise.
+
+        The HashMap is now wrapped in a NeverDestroyed object and is populated when the first
+        mark function is looked for.
+
+        * page/PerformanceUserTiming.cpp:
+        (WebCore::UserTiming::mark):
+        (WebCore::UserTiming::findExistingMarkStartTime):
+
+2016-01-04  Zan Dobersek  <[email protected]>
+
         [TextureMapper] Move ClipStack into its own file
         https://bugs.webkit.org/show_bug.cgi?id=152661
 

Modified: trunk/Source/WebCore/page/PerformanceUserTiming.cpp (194577 => 194578)


--- trunk/Source/WebCore/page/PerformanceUserTiming.cpp	2016-01-05 07:41:39 UTC (rev 194577)
+++ trunk/Source/WebCore/page/PerformanceUserTiming.cpp	2016-01-05 07:46:14 UTC (rev 194578)
@@ -31,6 +31,7 @@
 #include "Performance.h"
 #include "PerformanceMark.h"
 #include "PerformanceMeasure.h"
+#include <wtf/NeverDestroyed.h>
 #include <wtf/dtoa/utils.h>
 #include <wtf/text/WTFString.h>
 
@@ -38,34 +39,40 @@
 
 namespace {
 
-typedef HashMap<String, NavigationTimingFunction> RestrictedKeyMap;
-static RestrictedKeyMap restrictedKeyMap()
+static NavigationTimingFunction restrictedMarkFunction(const String& markName)
 {
-    DEPRECATED_DEFINE_STATIC_LOCAL(RestrictedKeyMap, map, ());
-    if (map.isEmpty()) {
-        map.add("navigationStart", &PerformanceTiming::navigationStart);
-        map.add("unloadEventStart", &PerformanceTiming::unloadEventStart);
-        map.add("unloadEventEnd", &PerformanceTiming::unloadEventEnd);
-        map.add("redirectStart", &PerformanceTiming::redirectStart);
-        map.add("redirectEnd", &PerformanceTiming::redirectEnd);
-        map.add("fetchStart", &PerformanceTiming::fetchStart);
-        map.add("domainLookupStart", &PerformanceTiming::domainLookupStart);
-        map.add("domainLookupEnd", &PerformanceTiming::domainLookupEnd);
-        map.add("connectStart", &PerformanceTiming::connectStart);
-        map.add("connectEnd", &PerformanceTiming::connectEnd);
-        map.add("secureConnectionStart", &PerformanceTiming::secureConnectionStart);
-        map.add("requestStart", &PerformanceTiming::requestStart);
-        map.add("responseStart", &PerformanceTiming::responseStart);
-        map.add("responseEnd", &PerformanceTiming::responseEnd);
-        map.add("domLoading", &PerformanceTiming::domLoading);
-        map.add("domInteractive", &PerformanceTiming::domInteractive);
-        map.add("domContentLoadedEventStart", &PerformanceTiming::domContentLoadedEventStart);
-        map.add("domContentLoadedEventEnd", &PerformanceTiming::domContentLoadedEventEnd);
-        map.add("domComplete", &PerformanceTiming::domComplete);
-        map.add("loadEventStart", &PerformanceTiming::loadEventStart);
-        map.add("loadEventEnd", &PerformanceTiming::loadEventEnd);
+    using MapPair = std::pair<ASCIILiteral, NavigationTimingFunction>;
+    static const std::array<MapPair, 21> pairs = { {
+        MapPair{ ASCIILiteral("navigationStart"), &PerformanceTiming::navigationStart },
+        MapPair{ ASCIILiteral("unloadEventStart"), &PerformanceTiming::unloadEventStart },
+        MapPair{ ASCIILiteral("unloadEventEnd"), &PerformanceTiming::unloadEventEnd },
+        MapPair{ ASCIILiteral("redirectStart"), &PerformanceTiming::redirectStart },
+        MapPair{ ASCIILiteral("redirectEnd"), &PerformanceTiming::redirectEnd },
+        MapPair{ ASCIILiteral("fetchStart"), &PerformanceTiming::fetchStart },
+        MapPair{ ASCIILiteral("domainLookupStart"), &PerformanceTiming::domainLookupStart },
+        MapPair{ ASCIILiteral("domainLookupEnd"), &PerformanceTiming::domainLookupEnd },
+        MapPair{ ASCIILiteral("connectStart"), &PerformanceTiming::connectStart },
+        MapPair{ ASCIILiteral("connectEnd"), &PerformanceTiming::connectEnd },
+        MapPair{ ASCIILiteral("secureConnectionStart"), &PerformanceTiming::secureConnectionStart },
+        MapPair{ ASCIILiteral("requestStart"), &PerformanceTiming::requestStart },
+        MapPair{ ASCIILiteral("responseStart"), &PerformanceTiming::responseStart },
+        MapPair{ ASCIILiteral("responseEnd"), &PerformanceTiming::responseEnd },
+        MapPair{ ASCIILiteral("domLoading"), &PerformanceTiming::domLoading },
+        MapPair{ ASCIILiteral("domInteractive"), &PerformanceTiming::domInteractive },
+        MapPair{ ASCIILiteral("domContentLoadedEventStart"), &PerformanceTiming::domContentLoadedEventStart },
+        MapPair{ ASCIILiteral("domContentLoadedEventEnd"), &PerformanceTiming::domContentLoadedEventEnd },
+        MapPair{ ASCIILiteral("domComplete"), &PerformanceTiming::domComplete },
+        MapPair{ ASCIILiteral("loadEventStart"), &PerformanceTiming::loadEventStart },
+        MapPair{ ASCIILiteral("loadEventEnd"), &PerformanceTiming::loadEventEnd },
+    } };
+
+    static NeverDestroyed<HashMap<String, NavigationTimingFunction>> map;
+    if (map.get().isEmpty()) {
+        for (auto& pair : pairs)
+            map.get().add(pair.first, pair.second);
     }
-    return map;
+
+    return map.get().get(markName);
 }
 
 } // namespace anonymous
@@ -98,7 +105,7 @@
 void UserTiming::mark(const String& markName, ExceptionCode& ec)
 {
     ec = 0;
-    if (restrictedKeyMap().contains(markName)) {
+    if (restrictedMarkFunction(markName)) {
         ec = SYNTAX_ERR;
         return;
     }
@@ -119,8 +126,8 @@
     if (m_marksMap.contains(markName))
         return m_marksMap.get(markName).last()->startTime();
 
-    if (restrictedKeyMap().contains(markName)) {
-        double value = static_cast<double>((m_performance->timing()->*(restrictedKeyMap().get(markName)))());
+    if (auto function = restrictedMarkFunction(markName)) {
+        double value = static_cast<double>((m_performance->timing()->*(function))());
         if (!value) {
             ec = INVALID_ACCESS_ERR;
             return 0.0;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to