Title: [278269] trunk/Source/WebCore
Revision
278269
Author
wei...@apple.com
Date
2021-05-30 21:22:39 -0700 (Sun, 30 May 2021)

Log Message

Use SortedArrayMap in parseColorContrastFunctionParameters
https://bugs.webkit.org/show_bug.cgi?id=226444

Reviewed by Darin Adler.

Use SortedArrayMap to remove some boilerplate and allow for a future where
this list gets big and the map can switch to a binary search automatically.

* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::parseColorContrastFunctionParameters):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (278268 => 278269)


--- trunk/Source/WebCore/ChangeLog	2021-05-31 03:44:27 UTC (rev 278268)
+++ trunk/Source/WebCore/ChangeLog	2021-05-31 04:22:39 UTC (rev 278269)
@@ -1,5 +1,18 @@
 2021-05-30  Sam Weinig  <wei...@apple.com>
 
+        Use SortedArrayMap in parseColorContrastFunctionParameters
+        https://bugs.webkit.org/show_bug.cgi?id=226444
+
+        Reviewed by Darin Adler.
+
+        Use SortedArrayMap to remove some boilerplate and allow for a future where
+        this list gets big and the map can switch to a binary search automatically.
+
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::parseColorContrastFunctionParameters):
+
+2021-05-30  Sam Weinig  <wei...@apple.com>
+
         Remove support for no longer specific color(lab ...) syntax
         https://bugs.webkit.org/show_bug.cgi?id=226439
 

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (278268 => 278269)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-05-31 03:44:27 UTC (rev 278268)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-05-31 04:22:39 UTC (rev 278269)
@@ -49,6 +49,7 @@
 #include "RuntimeEnabledFeatures.h"
 #include "StyleColor.h"
 #include "WebKitFontFamilyNames.h"
+#include <wtf/SortedArrayMap.h>
 #include <wtf/text/StringConcatenateNumbers.h>
 
 namespace WebCore {
@@ -1697,22 +1698,18 @@
     if (colorsToCompareAgainst.size() == 1)
         return { };
 
-    constexpr std::pair<CSSValueID, double> targetLuminanceMappings[] {
-        { CSSValueAA, 4.5 },
-        { CSSValueAALarge, 3.0 },
-        { CSSValueAAA, 7.0 },
-        { CSSValueAAALarge, 4.5 },
-    };
-
     if (consumedTo) {
         auto targetContrast = [&] () -> std::optional<double> {
             if (args.peek().type() == IdentToken) {
-                auto id = args.consumeIncludingWhitespace().id();
-                for (auto& [identifier, luminance] : targetLuminanceMappings) {
-                    if (identifier == id)
-                        return luminance;
-                }
-                return std::nullopt;
+                static constexpr std::pair<CSSValueID, double> targetContrastMappings[] {
+                    { CSSValueAA, 4.5 },
+                    { CSSValueAALarge, 3.0 },
+                    { CSSValueAAA, 7.0 },
+                    { CSSValueAAALarge, 4.5 },
+                };
+                static constexpr SortedArrayMap targetContrastMap { targetContrastMappings };
+                auto value = targetContrastMap.tryGet(args.consumeIncludingWhitespace().id());
+                return value ? std::make_optional(*value) : std::nullopt;
             }
             return consumeNumberRaw(args);
         }();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to