AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

75

TVGetTextSlab: Cache last used slab, it's probably the same

Avoids walking the slab list every time. Also in TVApplyStyle, check
that we actually need to call Text{Font,Face,Size}.

jcs made amendment 75 about 1 month ago
--- textview.c Wed Oct 14 17:45:06 2026 +++ textview.c Wed Oct 14 21:59:03 2026 @@ -355,6 +355,7 @@ TVClear(TVHandle tvh) slab->next_slab = NULL; HUnlock(tv->first_text_slab); + tv->text_slab_hint = NULL; tv->text_length = 0; tv->nlines = 0; tv->last_space = 0; @@ -441,7 +442,6 @@ TVUnlock(struct TVRec *tv) slabh = tv->first_style_slab; while (slabh) { - HLock(slabh); slab = (struct TVSlab *)*slabh; tslabh = slabh; slabh = slab->next_slab; --- textview.h Wed Oct 14 16:43:49 2026 +++ textview.h Wed Oct 14 21:58:25 2026 @@ -136,6 +136,7 @@ struct TVRec { Handle first_text_slab; Handle last_text_slab; + Handle text_slab_hint; #define TV_TEXT_SLAB_SIZE (8 * 1024) unsigned long text_length; unsigned long last_space; --- tv_store.c Wed Oct 14 16:51:42 2026 +++ tv_store.c Wed Oct 14 22:27:58 2026 @@ -37,7 +37,6 @@ TVAllocateSlab(struct TVRec *tv, unsigned long size, H return NULL; } id = slab->id + 1; - /* caller must HUnlock(*last) */ } slabh = NewHandleClear(sizeof(struct TVSlab) + size); @@ -51,7 +50,6 @@ TVAllocateSlab(struct TVRec *tv, unsigned long size, H slab->size = size; if (last != NULL && *last != NULL) { - HLock(*last); lslab = (struct TVSlab *)**last; lslab->next_slab = slabh; slab->prev_slab = *last; @@ -88,13 +86,24 @@ TVGetTextSlab(struct TVRec *tv, unsigned long addr) Handle slabh; struct TVSlab *slab; + slabh = tv->text_slab_hint; + if (slabh) { + HLock(slabh); + slab = (struct TVSlab *)*slabh; + if (addr >= slab->base && addr < slab->base + slab->size) + /* leave locked */ + return slab; + } + slabh = tv->first_text_slab; while (slabh) { HLock(slabh); slab = (struct TVSlab *)*slabh; - if (addr >= slab->base && addr < slab->base + slab->size) + if (addr >= slab->base && addr < slab->base + slab->size) { /* leave locked */ + tv->text_slab_hint = slabh; return slab; + } slabh = slab->next_slab; } @@ -211,6 +220,10 @@ TVGetLine(struct TVRec *tv, unsigned long line) void TVApplyStyle(struct TVStyle *style) { + if (thePort->txFont == style->font && thePort->txFace == style->style && + thePort->txSize == style->size) + return; + TextFont(style->font); TextFace(style->style); TextSize(style->size);