Use iterator to avoid walking all spans every time.

This commit is contained in:
Nicholas Marriott
2026-06-16 22:44:43 +01:00
parent 20ef8bd1c9
commit 2af751d78d
3 changed files with 15 additions and 7 deletions

View File

@@ -1462,13 +1462,15 @@ screen_redraw_draw(struct client *c, struct window_pane *wp, int flags)
/* Get cell type for offset from span. */ /* Get cell type for offset from span. */
int 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; u_int start, end;
if (span->data.type != REDRAW_SPAN_STATUS) if (span == NULL || span->data.type != REDRAW_SPAN_STATUS)
return (CELL_LEFTRIGHT); return (CELL_LEFTRIGHT);
wp = span->data.st.wp;
for (; span != NULL; span = TAILQ_NEXT(span, entry)) { for (; span != NULL; span = TAILQ_NEXT(span, entry)) {
if (span->data.type != REDRAW_SPAN_STATUS) if (span->data.type != REDRAW_SPAN_STATUS)
continue; continue;
@@ -1477,12 +1479,18 @@ screen_redraw_get_span_cell_type(struct redraw_span *span, u_int x)
start = span->data.st.offset; start = span->data.st.offset;
end = start + span->width; end = start + span->width;
if (x >= start && x < end) if (x >= start && x < end) {
*spanp = span;
return (span->data.st.cell_type); return (span->data.st.cell_type);
}
if (start > x) if (start > x) {
*spanp = span;
break; break;
}
} }
if (span == NULL)
*spanp = NULL;
return (CELL_LEFTRIGHT); return (CELL_LEFTRIGHT);
} }

2
tmux.h
View File

@@ -3367,7 +3367,7 @@ void screen_write_alternateoff(struct screen_write_ctx *,
void screen_redraw_screen(struct client *); void screen_redraw_screen(struct client *);
void screen_redraw_pane(struct client *, struct window_pane *); void screen_redraw_pane(struct client *, struct window_pane *);
void screen_redraw_pane_scrollbar(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 */ /* screen.c */
void screen_init(struct screen *, u_int, u_int, u_int); void screen_init(struct screen *, u_int, u_int, u_int);

View File

@@ -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); window_pane_get_border_style(wp, c, &gc);
pane_lines = window_pane_get_pane_lines(wp); pane_lines = window_pane_get_pane_lines(wp);
for (i = 0; i < width; i++) { 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); window_get_border_cell(wp->window, wp, pane_lines, cell_type, &gc);
screen_write_cell(&ctx, &gc); screen_write_cell(&ctx, &gc);
} }