Skip to content
Permalink
Browse files
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
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295461 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
litherum committed Jun 10, 2022
1 parent 06b0285 commit cf543cc5a7e7735d40e7440248c86761a3a9c68c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
@@ -67,6 +67,7 @@ set(WTF_PUBLIC_HEADERS
EmbeddedFixedVector.h
EnumClassOperatorOverloads.h
EnumTraits.h
EnumeratedArray.h
Expected.h
ExperimentalFeatureNames.h
ExportMacros.h
@@ -31,12 +31,11 @@ namespace WebCore {
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)
@@ -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 @@ class SystemFontDatabase {
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 @@ class SystemFontDatabase {
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;
};

0 comments on commit cf543cc

Please sign in to comment.