⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 263282 in webkit


Ignore:
Timestamp:
Jun 19, 2020, 1:13:14 PM (6 years ago)
Author:
Chris Dumez
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):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r263281 r263282  
     12020-06-19  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] RenderThemeIOS::cssValueToSystemColorMap() does an unnecessary linear search under systemColorFromCSSValueID()
     4        https://bugs.webkit.org/show_bug.cgi?id=213396
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        RenderThemeIOS::cssValueToSystemColorMap() does an unnecessary linear search under systemColorFromCSSValueID().
     9        cssValueToSystemColorMap() already has the selector, yet it passes a CSSValueID to systemColorFromCSSValueID() which
     10        then does a linear search to match the CSSValueID to a selector. This was very inefficient / unfortunate.
     11
     12        This patch introduces a systemColorFromCSSValueIDSelector() which takes in a selector instead of a CSSValueID. I have
     13        also moved the constructor of the LocalCurrentTraitCollection variable to the call site so that we don't keep
     14        constructing / destroying it for each loop iteration. The traces show us spending a lot of time in its constructor /
     15        destructor.
     16
     17        * rendering/RenderThemeIOS.mm:
     18        (WebCore::systemColorFromCSSValueIDSelector):
     19        (WebCore::RenderThemeIOS::cssValueToSystemColorMap):
     20
    1212020-06-19  James Darpinian  <jdarpinian@chromium.org>
    222
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r263278 r263282  
    12841284}
    12851285
     1286static inline Optional<Color> systemColorFromCSSValueIDSelector(CSSValueIDAndSelector idAndSelector)
     1287{
     1288    if (auto color = wtfObjCMsgSend<UIColor *>(PAL::getUIColorClass(), idAndSelector.selector))
     1289        return Color { color.CGColor, Color::Semantic };
     1290    return WTF::nullopt;
     1291}
     1292
    12861293static Optional<Color> systemColorFromCSSValueID(CSSValueID cssValueID, bool useDarkAppearance, bool useElevatedUserInterfaceLevel)
    12871294{
     
    13151322    static const NeverDestroyed<CSSValueToSystemColorMap> colorMap = [] {
    13161323        CSSValueToSystemColorMap map;
    1317         for (auto& cssValueIDSelector : cssValueIDSelectorList()) {
    1318             for (bool useDarkAppearance : { false, true }) {
    1319                 for (bool useElevatedUserInterfaceLevel : { false, true }) {
    1320                     if (auto color = systemColorFromCSSValueID(cssValueIDSelector.cssValueID, useDarkAppearance, useElevatedUserInterfaceLevel))
    1321                         map.add(CSSValueKey { cssValueIDSelector.cssValueID, useDarkAppearance, useElevatedUserInterfaceLevel }, *color);
     1324        for (bool useDarkAppearance : { false, true }) {
     1325            for (bool useElevatedUserInterfaceLevel : { false, true }) {
     1326                LocalCurrentTraitCollection localTraitCollection(useDarkAppearance, useElevatedUserInterfaceLevel);
     1327                for (auto& cssValueIDSelector : cssValueIDSelectorList()) {
     1328                    if (auto color = systemColorFromCSSValueIDSelector(cssValueIDSelector))
     1329                        map.add(CSSValueKey { cssValueIDSelector.cssValueID, useDarkAppearance, useElevatedUserInterfaceLevel }, WTFMove(*color));
    13221330                }
    13231331            }
Note: See TracChangeset for help on using the changeset viewer.