Title: [263282] trunk/Source/WebCore
Revision
263282
Author
cdu...@apple.com
Date
2020-06-19 13:13:14 -0700 (Fri, 19 Jun 2020)

Log Message

[iOS] RenderThemeIOS::cssValueToSystemColorMap() does an unnecessary linear search under systemColorFromCSSValueID()
https://bugs.webkit.org/show_bug.cgi?id=213396

Reviewed by Timothy Hatcher.

RenderThemeIOS::cssValueToSystemColorMap() does an unnecessary linear search under systemColorFromCSSValueID().
cssValueToSystemColorMap() already has the selector, yet it passes a CSSValueID to systemColorFromCSSValueID() which
then does a linear search to match the CSSValueID to a selector. This was very inefficient / unfortunate.

This patch introduces a systemColorFromCSSValueIDSelector() which takes in a selector instead of a CSSValueID. I have
also moved the constructor of the LocalCurrentTraitCollection variable to the call site so that we don't keep
constructing / destroying it for each loop iteration. The traces show us spending a lot of time in its constructor /
destructor.

* rendering/RenderThemeIOS.mm:
(WebCore::systemColorFromCSSValueIDSelector):
(WebCore::RenderThemeIOS::cssValueToSystemColorMap):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (263281 => 263282)


--- trunk/Source/WebCore/ChangeLog	2020-06-19 19:59:28 UTC (rev 263281)
+++ trunk/Source/WebCore/ChangeLog	2020-06-19 20:13:14 UTC (rev 263282)
@@ -1,3 +1,23 @@
+2020-06-19  Chris Dumez  <cdu...@apple.com>
+
+        [iOS] RenderThemeIOS::cssValueToSystemColorMap() does an unnecessary linear search under systemColorFromCSSValueID()
+        https://bugs.webkit.org/show_bug.cgi?id=213396
+
+        Reviewed by Timothy Hatcher.
+
+        RenderThemeIOS::cssValueToSystemColorMap() does an unnecessary linear search under systemColorFromCSSValueID().
+        cssValueToSystemColorMap() already has the selector, yet it passes a CSSValueID to systemColorFromCSSValueID() which
+        then does a linear search to match the CSSValueID to a selector. This was very inefficient / unfortunate.
+
+        This patch introduces a systemColorFromCSSValueIDSelector() which takes in a selector instead of a CSSValueID. I have
+        also moved the constructor of the LocalCurrentTraitCollection variable to the call site so that we don't keep
+        constructing / destroying it for each loop iteration. The traces show us spending a lot of time in its constructor /
+        destructor.
+
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::systemColorFromCSSValueIDSelector):
+        (WebCore::RenderThemeIOS::cssValueToSystemColorMap):
+
 2020-06-19  James Darpinian  <jdarpin...@chromium.org>
 
         [WebGL2] Uniform Buffer Objects

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (263281 => 263282)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2020-06-19 19:59:28 UTC (rev 263281)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2020-06-19 20:13:14 UTC (rev 263282)
@@ -1283,6 +1283,13 @@
     return cssValueIDSelectorList;
 }
 
+static inline Optional<Color> systemColorFromCSSValueIDSelector(CSSValueIDAndSelector idAndSelector)
+{
+    if (auto color = wtfObjCMsgSend<UIColor *>(PAL::getUIColorClass(), idAndSelector.selector))
+        return Color { color.CGColor, Color::Semantic };
+    return WTF::nullopt;
+}
+
 static Optional<Color> systemColorFromCSSValueID(CSSValueID cssValueID, bool useDarkAppearance, bool useElevatedUserInterfaceLevel)
 {
     LocalCurrentTraitCollection localTraitCollection(useDarkAppearance, useElevatedUserInterfaceLevel);
@@ -1314,11 +1321,12 @@
     ASSERT(RunLoop::isMain());
     static const NeverDestroyed<CSSValueToSystemColorMap> colorMap = [] {
         CSSValueToSystemColorMap map;
-        for (auto& cssValueIDSelector : cssValueIDSelectorList()) {
-            for (bool useDarkAppearance : { false, true }) {
-                for (bool useElevatedUserInterfaceLevel : { false, true }) {
-                    if (auto color = systemColorFromCSSValueID(cssValueIDSelector.cssValueID, useDarkAppearance, useElevatedUserInterfaceLevel))
-                        map.add(CSSValueKey { cssValueIDSelector.cssValueID, useDarkAppearance, useElevatedUserInterfaceLevel }, *color);
+        for (bool useDarkAppearance : { false, true }) {
+            for (bool useElevatedUserInterfaceLevel : { false, true }) {
+                LocalCurrentTraitCollection localTraitCollection(useDarkAppearance, useElevatedUserInterfaceLevel);
+                for (auto& cssValueIDSelector : cssValueIDSelectorList()) {
+                    if (auto color = systemColorFromCSSValueIDSelector(cssValueIDSelector))
+                        map.add(CSSValueKey { cssValueIDSelector.cssValueID, useDarkAppearance, useElevatedUserInterfaceLevel }, WTFMove(*color));
                 }
             }
         }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to