From a2b960979379b641830920bfed2a3fb0f9e30b72 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 16 Mar 2022 13:11:26 +0100 Subject: [PATCH] LibGfx: Make FontDatabase API use FlyString for family and variant This reduces work done by font lookups. --- Userland/Libraries/LibGfx/FontDatabase.cpp | 5 +++-- Userland/Libraries/LibGfx/FontDatabase.h | 4 ++-- Userland/Libraries/LibGfx/Typeface.h | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibGfx/FontDatabase.cpp b/Userland/Libraries/LibGfx/FontDatabase.cpp index 51da859afc..d184a70bdb 100644 --- a/Userland/Libraries/LibGfx/FontDatabase.cpp +++ b/Userland/Libraries/LibGfx/FontDatabase.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -164,7 +165,7 @@ RefPtr FontDatabase::get_by_name(StringView name) return it->value; } -RefPtr FontDatabase::get(String const& family, unsigned size, unsigned weight, unsigned slope, Font::AllowInexactSizeMatch allow_inexact_size_match) +RefPtr FontDatabase::get(FlyString const& family, unsigned size, unsigned weight, unsigned slope, Font::AllowInexactSizeMatch allow_inexact_size_match) { for (auto typeface : m_private->typefaces) { if (typeface->family() == family && typeface->weight() == weight && typeface->slope() == slope) @@ -173,7 +174,7 @@ RefPtr FontDatabase::get(String const& family, unsigned size, unsigne return nullptr; } -RefPtr FontDatabase::get(String const& family, const String& variant, unsigned size, Font::AllowInexactSizeMatch allow_inexact_size_match) +RefPtr FontDatabase::get(FlyString const& family, FlyString const& variant, unsigned size, Font::AllowInexactSizeMatch allow_inexact_size_match) { for (auto typeface : m_private->typefaces) { if (typeface->family() == family && typeface->variant() == variant) diff --git a/Userland/Libraries/LibGfx/FontDatabase.h b/Userland/Libraries/LibGfx/FontDatabase.h index f475fec169..5e3a5af819 100644 --- a/Userland/Libraries/LibGfx/FontDatabase.h +++ b/Userland/Libraries/LibGfx/FontDatabase.h @@ -44,8 +44,8 @@ public: static void set_fixed_width_font_query(String); static void set_default_fonts_lookup_path(String); - RefPtr get(const String& family, unsigned size, unsigned weight, unsigned slope, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No); - RefPtr get(const String& family, const String& variant, unsigned size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No); + RefPtr get(FlyString const& family, unsigned size, unsigned weight, unsigned slope, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No); + RefPtr get(FlyString const& family, FlyString const& variant, unsigned size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No); RefPtr get_by_name(StringView); void for_each_font(Function); void for_each_fixed_width_font(Function); diff --git a/Userland/Libraries/LibGfx/Typeface.h b/Userland/Libraries/LibGfx/Typeface.h index 3e8cb27c0c..b4f0de23f6 100644 --- a/Userland/Libraries/LibGfx/Typeface.h +++ b/Userland/Libraries/LibGfx/Typeface.h @@ -6,9 +6,9 @@ #pragma once +#include #include #include -#include #include #include #include @@ -24,8 +24,8 @@ public: { } - String family() const { return m_family; } - String variant() const { return m_variant; } + FlyString const& family() const { return m_family; } + FlyString const& variant() const { return m_variant; } unsigned weight() const; u8 slope() const; @@ -39,8 +39,8 @@ public: RefPtr get_font(unsigned size, Font::AllowInexactSizeMatch = Font::AllowInexactSizeMatch::No) const; private: - String m_family; - String m_variant; + FlyString m_family; + FlyString m_variant; Vector> m_bitmap_fonts; RefPtr m_ttf_font;