jcs
/textview
/amendments
/93
TVFindStyle: Avoid GetFontInfo for styles with same font
Each style can have the same font but with different bitmap info,
and in these cases we can avoid GetFontInfo and re-use the existing
width cache.
jcs made amendment 93 20 days ago
--- tv_store.c Tue Nov 3 15:38:45 2026
+++ tv_store.c Tue Nov 3 23:00:36 2026
@@ -282,12 +282,13 @@ TVFindStyle(struct TVRec *tv, struct TVStyle *style)
{
Handle slabh;
struct TVSlab *slab;
- struct TVStyle *tstyle;
+ struct TVStyle *tstyle, *same_font;
unsigned long size;
if (style->loc)
return TVGetStyle(tv, style->loc);
+ same_font = NULL;
slabh = tv->first_style_slab;
while (slabh) {
HLock(slabh);
@@ -298,9 +299,16 @@ iterate_slab:
if (tstyle->loc == 0)
goto next_slab;
- if (!ARE_STYLES_EQUAL(tstyle, style))
+ if (!ARE_STYLES_EQUAL(tstyle, style)) {
+ /* but if it's the same in basic font metrics, use it */
+ if (same_font == NULL && !tstyle->bitmap_data_size &&
+ tstyle->font == style->font &&
+ tstyle->style == style->style &&
+ tstyle->size == style->size)
+ same_font = tstyle;
goto next_style;
-
+ }
+
if (tstyle->bitmap_data_size &&
memcmp(tstyle->bitmap_data, style->bitmap.baseAddr,
tstyle->bitmap_data_size) != 0)
@@ -375,7 +383,11 @@ create_style:
}
TVApplyStyle(tstyle);
- if (!style->bitmap_data_size || style->font_info.widMax == 0)
+ if (!style->bitmap_data_size && same_font != NULL) {
+ tstyle->font_info = same_font->font_info;
+ memcpy(tstyle->width_cache, same_font->width_cache,
+ sizeof(tstyle->width_cache));
+ } else if (!style->bitmap_data_size || style->font_info.widMax == 0)
GetFontInfo(&tstyle->font_info);
tv->cur_style = tstyle->loc;