From b25cfdd3051333e3d226b26aba8dd37aefb5f9f1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 5 Sep 2019 19:03:58 -0400 Subject: [PATCH 1/2] FontCache: Default destructor within the cpp file Avoids potentially inlining a lot of repeated destruction logic. This also allows the class to play nicer with forward declarations. While we're at it, we can also explicitly delete the move assignment/constructor (previously they were implicitly deleted, given the class contains a const reference). --- specter/include/specter/FontCache.hpp | 2 ++ specter/lib/FontCache.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/specter/include/specter/FontCache.hpp b/specter/include/specter/FontCache.hpp index fc291e426..fe1f14e03 100644 --- a/specter/include/specter/FontCache.hpp +++ b/specter/include/specter/FontCache.hpp @@ -176,6 +176,8 @@ class FontCache { public: FontCache(const hecl::Runtime::FileStoreManager& fileMgr); + ~FontCache(); + FontCache(const FontCache& other) = delete; FontCache& operator=(const FontCache& other) = delete; diff --git a/specter/lib/FontCache.cpp b/specter/lib/FontCache.cpp index 1add829ac..c6ba42461 100644 --- a/specter/lib/FontCache.cpp +++ b/specter/lib/FontCache.cpp @@ -613,6 +613,8 @@ FontCache::FontCache(const hecl::Runtime::FileStoreManager& fileMgr) hecl::MakeDir(m_cacheRoot.c_str()); } +FontCache::~FontCache() = default; + FontTag FontCache::prepCustomFont(std::string_view name, FT_Face face, FCharFilter filter, bool subpixel, float points, uint32_t dpi) { /* Quick validation */ From 5c54fd73a1ce48ebc0e23e6a96d0f46995bfb298 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 5 Sep 2019 19:19:06 -0400 Subject: [PATCH 2/2] FontCache: Make filters non-allocating Avoids the creation of three allocating static constructors that run during program start. --- specter/include/specter/FontCache.hpp | 3 +-- specter/lib/FontCache.cpp | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/specter/include/specter/FontCache.hpp b/specter/include/specter/FontCache.hpp index fe1f14e03..88155ca00 100644 --- a/specter/include/specter/FontCache.hpp +++ b/specter/include/specter/FontCache.hpp @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -66,7 +65,7 @@ public: } }; -using FCharFilter = std::pair>; +using FCharFilter = std::pair; class FontAtlas { FT_Face m_face; diff --git a/specter/lib/FontCache.cpp b/specter/lib/FontCache.cpp index c6ba42461..db491ec09 100644 --- a/specter/lib/FontCache.cpp +++ b/specter/lib/FontCache.cpp @@ -43,15 +43,16 @@ extern "C" const FT_Driver_ClassRec tt_driver_class; namespace specter { static logvisor::Module Log("specter::FontCache"); -const FCharFilter AllCharFilter = std::make_pair("all-glyphs", [](uint32_t) -> bool { return true; }); +const FCharFilter AllCharFilter{"all-glyphs", [](uint32_t) { return true; }}; -const FCharFilter LatinCharFilter = - std::make_pair("latin-glyphs", [](uint32_t c) -> bool { return c <= 0xff || ((c - 0x2200) <= (0x23FF - 0x2200)); }); +const FCharFilter LatinCharFilter{"latin-glyphs", + [](uint32_t c) { return c <= 0xff || (c - 0x2200) <= (0x23FF - 0x2200); }}; -const FCharFilter LatinAndJapaneseCharFilter = std::make_pair("latin-and-jp-glyphs", [](uint32_t c) -> bool { - return LatinCharFilter.second(c) || ((c - 0x2E00) <= (0x30FF - 0x2E00)) || ((c - 0x4E00) <= (0x9FFF - 0x4E00)) || - ((c - 0xFF00) <= (0xFFEF - 0xFF00)); -}); +const FCharFilter LatinAndJapaneseCharFilter{"latin-and-jp-glyphs", [](uint32_t c) { + return LatinCharFilter.second(c) || (c - 0x2E00) <= (0x30FF - 0x2E00) || + (c - 0x4E00) <= (0x9FFF - 0x4E00) || + (c - 0xFF00) <= (0xFFEF - 0xFF00); + }}; FontTag::FontTag(std::string_view name, bool subpixel, float points, uint32_t dpi) { XXH64_state_t st; @@ -628,10 +629,11 @@ FontTag FontCache::prepCustomFont(std::string_view name, FT_Face face, FCharFilt FT_Set_Char_Size(face, 0, points * 64.0, 0, dpi); /* Make tag and search for cached version */ - FontTag tag(std::string(name) + '_' + filter.first, subpixel, points, dpi); - auto search = m_cachedAtlases.find(tag); - if (search != m_cachedAtlases.end()) + const FontTag tag(std::string(name).append(1, '_').append(filter.first), subpixel, points, dpi); + const auto search = m_cachedAtlases.find(tag); + if (search != m_cachedAtlases.end()) { return tag; + } /* Now check filesystem cache */ hecl::SystemString cachePath = m_cacheRoot + _SYS_STR('/') + fmt::format(fmt(_SYS_STR("{}")), tag.hash());