Skip to content

Commit

Permalink
Special-casing the zero glyph page is unnecessary (Part 2)
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259257
rdar://112344047

Reviewed by Cameron McCormack.

This is a follow-up to 266052@main. Each glyph page only holds 16 characters, so the
0th glyph page isn't really special. Almost no text will actually use it. So there's
no need to special-case it. (I bet that this special-case wasn't actually created
for performance, but just because of how our HashMaps treat 0 as empty...)

* Source/WebCore/platform/graphics/Font.cpp:
(WebCore::Font::glyphPage const):
* Source/WebCore/platform/graphics/Font.h:

Canonical link: https://commits.webkit.org/266091@main
  • Loading branch information
litherum committed Jul 16, 2023
1 parent 638ac81 commit 68a63d5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
5 changes: 0 additions & 5 deletions Source/WebCore/platform/graphics/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,6 @@ static RefPtr<GlyphPage> createAndFillGlyphPage(unsigned pageNumber, const Font&

const GlyphPage* Font::glyphPage(unsigned pageNumber) const
{
if (!pageNumber) {
if (!m_glyphPageZero)
m_glyphPageZero = createAndFillGlyphPage(0, *this);
return m_glyphPageZero.get();
}
auto addResult = m_glyphPages.add(pageNumber, nullptr);
if (addResult.isNewEntry)
addResult.iterator->value = createAndFillGlyphPage(pageNumber, *this);
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/platform/graphics/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ class Font : public RefCounted<Font> {

const FontPlatformData m_platformData;

mutable RefPtr<GlyphPage> m_glyphPageZero;
mutable HashMap<unsigned, RefPtr<GlyphPage>> m_glyphPages;
mutable HashMap<unsigned, RefPtr<GlyphPage>, IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> m_glyphPages;
mutable GlyphMetricsMap<float> m_glyphToWidthMap;
mutable std::unique_ptr<GlyphMetricsMap<FloatRect>> m_glyphToBoundsMap;
// FIXME: Find a more efficient way to represent std::optional<Path>.
Expand Down

0 comments on commit 68a63d5

Please sign in to comment.