Title: [295461] trunk/Source
Revision
295461
Author
mmaxfi...@apple.com
Date
2022-06-10 13:36:55 -0700 (Fri, 10 Jun 2022)

Log Message

Adopt EnumeratedArray in SystemFontDatabase
https://bugs.webkit.org/show_bug.cgi?id=241506

Reviewed by Cameron McCormack.

This is why we created EnumeratedArray in the first place.

* Source/WebCore/platform/graphics/SystemFontDatabase.cpp:
(WebCore::SystemFontDatabase::systemFontShorthandInfo const):
* Source/WebCore/platform/graphics/SystemFontDatabase.h:

Canonical link: https://commits.webkit.org/251467@main

Modified Paths

Diff

Modified: trunk/Source/WTF/wtf/CMakeLists.txt (295460 => 295461)


--- trunk/Source/WTF/wtf/CMakeLists.txt	2022-06-10 20:23:56 UTC (rev 295460)
+++ trunk/Source/WTF/wtf/CMakeLists.txt	2022-06-10 20:36:55 UTC (rev 295461)
@@ -67,6 +67,7 @@
     EmbeddedFixedVector.h
     EnumClassOperatorOverloads.h
     EnumTraits.h
+    EnumeratedArray.h
     Expected.h
     ExperimentalFeatureNames.h
     ExportMacros.h

Modified: trunk/Source/WebCore/platform/graphics/SystemFontDatabase.cpp (295460 => 295461)


--- trunk/Source/WebCore/platform/graphics/SystemFontDatabase.cpp	2022-06-10 20:23:56 UTC (rev 295460)
+++ trunk/Source/WebCore/platform/graphics/SystemFontDatabase.cpp	2022-06-10 20:36:55 UTC (rev 295461)
@@ -31,12 +31,11 @@
 SystemFontDatabase::SystemFontDatabase() = default;
 
 auto SystemFontDatabase::systemFontShorthandInfo(FontShorthand fontShorthand) -> const SystemFontShorthandInfo& {
-    auto index = static_cast<FontShorthandUnderlyingType>(fontShorthand);
-    if (auto& entry = m_systemFontShorthandCache[index])
+    if (auto& entry = m_systemFontShorthandCache[fontShorthand])
         return *entry;
 
-    m_systemFontShorthandCache[index] = platformSystemFontShorthandInfo(fontShorthand);
-    return *m_systemFontShorthandCache[index];
+    m_systemFontShorthandCache[fontShorthand] = platformSystemFontShorthandInfo(fontShorthand);
+    return *m_systemFontShorthandCache[fontShorthand];
 }
 
 const AtomString& SystemFontDatabase::systemFontShorthandFamily(FontShorthand fontShorthand)

Modified: trunk/Source/WebCore/platform/graphics/SystemFontDatabase.h (295460 => 295461)


--- trunk/Source/WebCore/platform/graphics/SystemFontDatabase.h	2022-06-10 20:23:56 UTC (rev 295460)
+++ trunk/Source/WebCore/platform/graphics/SystemFontDatabase.h	2022-06-10 20:36:55 UTC (rev 295461)
@@ -28,6 +28,7 @@
 #include "FontSelectionAlgorithm.h"
 #include <array>
 #include <optional>
+#include <wtf/EnumeratedArray.h>
 #include <wtf/text/AtomString.h>
 
 namespace WebCore {
@@ -65,10 +66,8 @@
         AppleSystemTitle3,
         AppleSystemTitle4,
 #endif
-        StatusBar,
+        StatusBar, // This has to be kept in sync with SystemFontShorthandCache below.
     };
-    using FontShorthandUnderlyingType = std::underlying_type<FontShorthand>::type;
-    static constexpr auto fontShorthandCount = static_cast<FontShorthandUnderlyingType>(FontShorthand::StatusBar) + 1;
 
     const AtomString& systemFontShorthandFamily(FontShorthand);
     float systemFontShorthandSize(FontShorthand);
@@ -88,7 +87,7 @@
     const SystemFontShorthandInfo& systemFontShorthandInfo(FontShorthand);
     static SystemFontShorthandInfo platformSystemFontShorthandInfo(FontShorthand);
 
-    using SystemFontShorthandCache = std::array<std::optional<SystemFontShorthandInfo>, fontShorthandCount>;
+    using SystemFontShorthandCache = EnumeratedArray<FontShorthand, std::optional<SystemFontShorthandInfo>, FontShorthand::StatusBar>;
     SystemFontShorthandCache m_systemFontShorthandCache;
 };
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to