AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

81

TVCalcLinesLocked: Simplify walking through text_slab_data


jcs made amendment 81 about 1 month ago
--- tv_layout.c Wed Oct 14 23:34:20 2026 +++ tv_layout.c Wed Oct 14 23:54:43 2026 @@ -122,14 +122,14 @@ Boolean TVCalcLinesLocked(struct TVRec *tv, Boolean ignore_dirty) { struct TVSlab *text_slab; - struct TVChunk *chunk, *tchunk, *last_chunk, *prev_chunk, *next_chunk; + struct TVChunk *chunk, *last_chunk, *prev_chunk; struct TVStyle *style; struct TVLine *line, *prev_line, *next_line; - unsigned long avail, start, nline, max_right; - long n, back_width, back_n, next_tabstop; - short width, height; + unsigned long start, nline; + long n; + short width, height, max_right; char *text_slab_data; - register unsigned char c; + register unsigned char *p, c; Boolean new_line; if (tv->first_chunk == 0) { @@ -218,15 +218,17 @@ reload_chunk: * Walk each character and find its width, possibly wrapping and * starting a new line. */ - for (n = start; n < chunk->end; n++) { - c = text_slab_data[n - text_slab->base]; + p = (unsigned char *)text_slab_data + (start - text_slab->base); + for (n = start; n < chunk->end; n++, p++) { + c = *p; if (c == '\r') { new_line = true; width = 0; } else { - width = TVCharWidth(tv, style, line, chunk->end_right, - c); + if (c == '\t' || !(width = style->width_cache[c])) + width = TVCharWidth(tv, style, line, chunk->end_right, + c); if (c == ' ' && !style->bitmap_data_size) { tv->last_space = n; @@ -243,6 +245,8 @@ reload_chunk: if (n >= chunk->start) { n = tv->last_space; + p = (unsigned char *)text_slab_data + + (n - text_slab->base); continue; } @@ -360,7 +364,6 @@ reload_chunk: line->indent = 0; } -done_chunks: tv->nlines = nline; line = TVGetLine(tv, nline);