jcs
/textview
/amendments
/69
TVAppendLocked: Check for slab full first
jcs made amendment 69 about 1 month ago
--- textview.c Wed Sep 30 17:32:24 2026
+++ textview.c Wed Oct 14 16:58:35 2026
@@ -518,6 +518,18 @@ TVAppendLocked(struct TVRec *tv, struct TVStyle *style
chunk = TVGetChunk(tv, tv->last_chunk);
while (length) {
+ avail = text_slab->size - text_slab->pos;
+ if (avail == 0) {
+ /* new text slab, new chunk */
+ if ((text_slabh = TVAllocateSlab(tv, TV_TEXT_SLAB_SIZE,
+ &tv->first_text_slab, &tv->last_text_slab)) == NULL)
+ return false;
+
+ text_slab = (struct TVSlab *)*text_slabh;
+ avail = text_slab->size;
+ new_chunk = true;
+ }
+
if (chunk == NULL || new_chunk) {
new_chunk = false;
prev_chunk_loc = chunk ? chunk->loc : 0;
@@ -533,20 +545,6 @@ TVAppendLocked(struct TVRec *tv, struct TVStyle *style
chunk->prev_chunk = prev_chunk->loc;
prev_chunk->next_chunk = chunk->loc;
}
- }
-
- avail = text_slab->size - text_slab->pos;
- if (avail == 0) {
- /* new text slab, new chunk */
- chunk->end = text_slab->base + text_slab->pos;
-
- if ((text_slabh = TVAllocateSlab(tv, TV_TEXT_SLAB_SIZE,
- &tv->first_text_slab, &tv->last_text_slab)) == NULL)
- return false;
- text_slab = (struct TVSlab *)*text_slabh;
-
- new_chunk = true;
- continue;
}
text_slab_data = text_slab->data + text_slab->pos;