From 2af751d78d9d1148cb5a7a609822ae4e7056d316 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 16 Jun 2026 22:44:43 +0100 Subject: [PATCH] Use iterator to avoid walking all spans every time. --- screen-redraw.c | 18 +++++++++++++----- tmux.h | 2 +- window-border.c | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/screen-redraw.c b/screen-redraw.c index 8b99cc20..fa1080f5 100644 --- a/screen-redraw.c +++ b/screen-redraw.c @@ -1462,13 +1462,15 @@ screen_redraw_draw(struct client *c, struct window_pane *wp, int flags) /* Get cell type for offset from span. */ int -screen_redraw_get_span_cell_type(struct redraw_span *span, u_int x) +screen_redraw_get_span_cell_type(struct redraw_span **spanp, u_int x) { - struct window_pane *wp = span->data.st.wp; + struct redraw_span *span = *spanp; + struct window_pane *wp; u_int start, end; - if (span->data.type != REDRAW_SPAN_STATUS) + if (span == NULL || span->data.type != REDRAW_SPAN_STATUS) return (CELL_LEFTRIGHT); + wp = span->data.st.wp; for (; span != NULL; span = TAILQ_NEXT(span, entry)) { if (span->data.type != REDRAW_SPAN_STATUS) continue; @@ -1477,12 +1479,18 @@ screen_redraw_get_span_cell_type(struct redraw_span *span, u_int x) start = span->data.st.offset; end = start + span->width; - if (x >= start && x < end) + if (x >= start && x < end) { + *spanp = span; return (span->data.st.cell_type); + } - if (start > x) + if (start > x) { + *spanp = span; break; + } } + if (span == NULL) + *spanp = NULL; return (CELL_LEFTRIGHT); } diff --git a/tmux.h b/tmux.h index 7315b149..ce55b724 100644 --- a/tmux.h +++ b/tmux.h @@ -3367,7 +3367,7 @@ void screen_write_alternateoff(struct screen_write_ctx *, void screen_redraw_screen(struct client *); void screen_redraw_pane(struct client *, struct window_pane *); void screen_redraw_pane_scrollbar(struct client *, struct window_pane *); -int screen_redraw_get_span_cell_type(struct redraw_span *, u_int); +int screen_redraw_get_span_cell_type(struct redraw_span **, u_int); /* screen.c */ void screen_init(struct screen *, u_int, u_int, u_int); diff --git a/window-border.c b/window-border.c index 56547b75..e64b5b01 100644 --- a/window-border.c +++ b/window-border.c @@ -145,7 +145,7 @@ window_make_pane_status(struct window_pane *wp, struct client *c, u_int width, window_pane_get_border_style(wp, c, &gc); pane_lines = window_pane_get_pane_lines(wp); for (i = 0; i < width; i++) { - cell_type = screen_redraw_get_span_cell_type(span, i); + cell_type = screen_redraw_get_span_cell_type(&span, i); window_get_border_cell(wp->window, wp, pane_lines, cell_type, &gc); screen_write_cell(&ctx, &gc); }