perf(text): fold Ensure+Lookup into FontAtlas::EnsureAndGet (#53)

Per glyph, ShapeText did cache_.contains(key) (in Ensure) then
cache_.find(key) (in Lookup) — two independent hashes + node-chases of
the same key. Add EnsureAndGet returning const Glyph* with a single
find, insert-on-miss, returning &it->second. It returns nullptr only on
ShelfPlace failure, preserving the existing `if (g==nullptr) continue;`
behavior. Ensure now delegates to it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
catbot 2026-06-16 15:43:58 +00:00
commit 77a6501ced
3 changed files with 13 additions and 6 deletions

View file

@ -75,8 +75,7 @@ std::uint32_t UIRenderer::ShapeText(Font& font, float pxSize,
if (cp == 0) break;
if (cp == '\n') { continue; }
fontAtlas->Ensure(font, cp);
const Glyph* g = fontAtlas->Lookup(font, cp);
const Glyph* g = fontAtlas->EnsureAndGet(font, cp);
if (g == nullptr) continue;
if (g->w > 0 && g->h > 0) {