jcs
/textview
/amendments
/90
TVGetChunk+TVGetStyle: Cache last-used chunk and style slabs too
jcs made amendment 90 22 days ago
--- textview.c Mon Nov 2 22:02:55 2026
+++ textview.c Tue Nov 3 15:33:49 2026
@@ -361,6 +361,8 @@ TVClear(TVHandle tvh)
HUnlock(tv->first_text_slab);
tv->text_slab_hint = NULL;
+ tv->style_slab_hint = NULL;
+ tv->chunk_slab_hint = NULL;
tv->text_length = 0;
tv->nlines = 0;
tv->last_space = 0;
--- textview.h Mon Nov 2 22:02:10 2026
+++ textview.h Tue Nov 3 15:33:16 2026
@@ -130,6 +130,7 @@ struct TVRec {
Handle first_style_slab;
Handle last_style_slab;
+ Handle style_slab_hint;
#define TV_STYLE_SLAB_SIZE (sizeof(struct TVStyle) * 16)
TVSlabLocator cur_style;
@@ -143,6 +144,7 @@ struct TVRec {
Handle first_chunk_slab;
Handle last_chunk_slab;
+ Handle chunk_slab_hint;
#define TV_CHUNK_SLAB_SIZE (sizeof(struct TVChunk) * 50)
TVSlabLocator first_chunk;
TVSlabLocator last_chunk;
--- tv_store.c Thu Oct 15 09:14:17 2026
+++ tv_store.c Tue Nov 3 15:38:45 2026
@@ -134,17 +134,27 @@ TVGetChunk(struct TVRec *tv, TVSlabLocator loc)
if (loc == 0)
return NULL;
- slabh = tv->first_chunk_slab;
- while (slabh) {
+ slabh = tv->chunk_slab_hint;
+ if (slabh) {
HLock(slabh);
slab = (struct TVSlab *)*slabh;
- if (slab->id == SLABLOC_SLABID(loc))
- break;
- slabh = slab->next_slab;
+ if (slab->id != SLABLOC_SLABID(loc))
+ slabh = NULL;
}
- if (slabh == NULL)
- return NULL;
-
+ if (slabh == NULL) {
+ slabh = tv->first_chunk_slab;
+ while (slabh) {
+ HLock(slabh);
+ slab = (struct TVSlab *)*slabh;
+ if (slab->id == SLABLOC_SLABID(loc))
+ break;
+ slabh = slab->next_slab;
+ }
+ if (slabh == NULL)
+ return NULL;
+ tv->chunk_slab_hint = slabh;
+ }
+
addr = slab->data + SLABLOC_OFFSET(loc);
if ((unsigned long)addr % 2 != 0) {
Debugger();
@@ -235,7 +245,16 @@ TVGetStyle(struct TVRec *tv, TVSlabLocator loc)
struct TVStyle *style;
short n;
- slabh = tv->first_style_slab;
+ slabh = tv->style_slab_hint;
+ if (slabh) {
+ HLock(slabh);
+ slab = (struct TVSlab *)*slabh;
+ if (slab->id != SLABLOC_SLABID(loc))
+ slabh = NULL;
+ }
+ if (slabh == NULL)
+ slabh = tv->first_style_slab;
+
while (slabh) {
HLock(slabh);
slab = (struct TVSlab *)*slabh;
@@ -251,6 +270,7 @@ TVGetStyle(struct TVRec *tv, TVSlabLocator loc)
Debugger();
return NULL;
}
+ tv->style_slab_hint = slabh;
return style;
}