Some trivial optimizations.

This commit is contained in:
Nicholas Marriott
2026-06-16 23:31:52 +01:00
parent 9212ecea84
commit 2ce8ff9e6d
2 changed files with 38 additions and 11 deletions

View File

@@ -405,7 +405,8 @@ layout_fix_panes(struct window *w, struct window_pane *skip)
struct window_pane *wp; struct window_pane *wp;
struct layout_cell *lc; struct layout_cell *lc;
int status, scrollbars, sb_pos, sb_w, sb_pad; int status, scrollbars, sb_pos, sb_w, sb_pad;
u_int sx, sy; int old_xoff, old_yoff, changed = 0;
u_int sx, sy, old_sx, old_sy;
status = window_get_pane_status(w); status = window_get_pane_status(w);
scrollbars = options_get_number(w->options, "pane-scrollbars"); scrollbars = options_get_number(w->options, "pane-scrollbars");
@@ -415,6 +416,11 @@ layout_fix_panes(struct window *w, struct window_pane *skip)
if ((lc = wp->layout_cell) == NULL || wp == skip) if ((lc = wp->layout_cell) == NULL || wp == skip)
continue; continue;
old_xoff = wp->xoff;
old_yoff = wp->yoff;
old_sx = wp->sx;
old_sy = wp->sy;
wp->xoff = lc->xoff; wp->xoff = lc->xoff;
wp->yoff = lc->yoff; wp->yoff = lc->yoff;
sx = lc->sx; sx = lc->sx;
@@ -452,8 +458,15 @@ layout_fix_panes(struct window *w, struct window_pane *skip)
} }
window_pane_resize(wp, sx, sy); window_pane_resize(wp, sx, sy);
if (wp->xoff != old_xoff ||
wp->yoff != old_yoff ||
wp->sx != old_sx ||
wp->sy != old_sy)
changed = 1;
} }
screen_redraw_invalidate_scene(w); if (changed)
screen_redraw_invalidate_scene(w);
} }
/* Count the number of available cells in a layout. */ /* Count the number of available cells in a layout. */
@@ -774,10 +787,15 @@ layout_resize_floating_pane_to(struct window_pane *wp, enum layout_type type,
return; return;
} }
if (type == LAYOUT_TOPBOTTOM) if (type == LAYOUT_TOPBOTTOM) {
if (lc->sy == size)
return;
lc->sy = size; lc->sy = size;
else } else {
if (lc->sx == size)
return;
lc->sx = size; lc->sx = size;
}
screen_redraw_invalidate_scene(wp->window); screen_redraw_invalidate_scene(wp->window);
} }
@@ -793,6 +811,8 @@ layout_resize_floating_pane(struct window_pane *wp, enum layout_type type,
*cause = xstrdup("pane is not floating"); *cause = xstrdup("pane is not floating");
return; return;
} }
if (change == 0)
return;
if (type == LAYOUT_TOPBOTTOM) { if (type == LAYOUT_TOPBOTTOM) {
size = lc->sy + change; size = lc->sy + change;

View File

@@ -164,6 +164,9 @@ struct redraw_build_cell {
struct redraw_span_data data; struct redraw_span_data data;
}; };
static struct redraw_build_cell *screen_redraw_cells;
static size_t screen_redraw_ncells;
/* Context for building the scene. */ /* Context for building the scene. */
struct redraw_build_ctx { struct redraw_build_ctx {
struct client *c; struct client *c;
@@ -864,22 +867,24 @@ screen_redraw_make_scene(struct client *c)
if (bctx.sx != 0 && bctx.sy > SIZE_MAX / bctx.sx) if (bctx.sx != 0 && bctx.sy > SIZE_MAX / bctx.sx)
fatalx("%s: too many cells", __func__); fatalx("%s: too many cells", __func__);
ncells = (size_t)bctx.sx * bctx.sy; ncells = (size_t)bctx.sx * bctx.sy;
if (ncells > SIZE_MAX / sizeof *bctx.cells) if (ncells > screen_redraw_ncells) {
fatalx("%s: too many cells", __func__); screen_redraw_cells = xreallocarray(screen_redraw_cells, ncells,
bctx.cells = xmalloc(ncells * sizeof *bctx.cells); sizeof *screen_redraw_cells);
screen_redraw_ncells = ncells;
}
bctx.cells = screen_redraw_cells;
for (y = 0; y < bctx.sy; y++) { for (y = 0; y < bctx.sy; y++) {
for (x = 0; x < bctx.sx; x++) for (x = 0; x < bctx.sx; x++)
screen_redraw_reset_cell(&bctx, x, y); screen_redraw_reset_cell(&bctx, x, y);
} }
TAILQ_FOREACH_REVERSE(wp, &bctx.w->z_index, window_panes_zindex, zentry) TAILQ_FOREACH_REVERSE(wp, &bctx.w->z_index, window_panes_zindex, zentry)
screen_redraw_mark_pane(&bctx, wp); screen_redraw_mark_pane(&bctx, wp);
screen_redraw_mark_two_pane_colours(&bctx); screen_redraw_mark_two_pane_colours(&bctx);
screen_redraw_finish_scene(&bctx, scene); screen_redraw_finish_scene(&bctx, scene);
log_debug("%s: finished @%u scene build", c->name, scene->w->id); log_debug("%s: finished @%u scene build", c->name, scene->w->id);
free(bctx.cells);
return (scene); return (scene);
} }
@@ -1463,8 +1468,10 @@ screen_redraw_draw(struct client *c, struct window_pane *wp, int flags)
} }
} }
log_debug("%s: starting @%u redraw (%s)", c->name, w->id, if (log_get_level() != 0) {
screen_redraw_flags_string(flags)); log_debug("%s: starting @%u redraw (%s)", c->name, w->id,
screen_redraw_flags_string(flags));
}
scene = screen_redraw_get_scene(c); scene = screen_redraw_get_scene(c);
if (scene == NULL) if (scene == NULL)