tryGet method
Returns a cached paragraph, or builds one if under the per-frame budget. Returns null when the budget is exhausted (the painter schedules a warmup frame and the glyph fills in next frame).
Implementation
ui.Paragraph? tryGet(int codepoint, int fg,
{bool bold = false, bool italic = false, bool wide = false}) {
final key = (codepoint << 27) ^
((bold ? 1 : 0) << 26) ^
((italic ? 1 : 0) << 25) ^
((wide ? 1 : 0) << 24) ^
(fg & 0xFFFFFF);
final existing = _cache.remove(key); // remove+reinsert = LRU touch
if (existing != null) {
_cache[key] = existing;
return existing;
}
if (_buildsThisFrame >= maxBuildsPerFrame) return null;
_buildsThisFrame++;
final p = _build(codepoint, fg, bold: bold, italic: italic, wide: wide);
_cache[key] = p;
if (_cache.length > maxEntries) {
_cache.remove(_cache.keys.first); // evict eldest
}
return p;
}