commit a00b4c97e6dd47ac8ada094890b515cfe6744607 from: Omar Polo date: Sun Jun 20 14:54:12 2021 UTC optimize redraw_window don't redraw the page if no scrolling happened. There's still need to ``force'' the redraw sometimes, like after a resize or after toggling olivetti-mode, so add a buffer->force_redraw flag for it. commit - f9560742eabf2ce27a6204047984be113db92642 commit + a00b4c97e6dd47ac8ada094890b515cfe6744607 blob - d56d1135ac820f016d1e15baa26b4149dfc2dd73 blob + ae84fd1733a499d1c4f7f3d5002172687c81fde2 --- telescope.h +++ telescope.h @@ -171,6 +171,10 @@ struct hist { struct buffer { struct parser page; + + size_t last_line_off; + int force_redraw; + int curs_x; int curs_y; size_t line_off; blob - dd9149bc39d552f9f124461aee85788c9ef010ad blob + 82a0fedd736cd241035a1e18f08fabc0f32e5a95 --- ui.c +++ ui.c @@ -1352,6 +1352,7 @@ wrap_page(struct buffer *buffer, int width) : buffer->current_line->parent; buffer->current_line = NULL; + buffer->force_redraw = 1; buffer->curs_y = 0; buffer->line_off = 0; @@ -1518,12 +1519,24 @@ redraw_window(WINDOW *win, int height, struct buffer * { struct vline *vl; int l; + + /* + * Don't bother redraw the body if nothing changed. Cursor + * movements count as "nothing changed" if it hasn't produced + * a scroll. Ensure that wmove is called though! + */ + if (!buffer->force_redraw && + buffer->last_line_off == buffer->line_off) + goto end; werase(win); buffer->line_off = MIN(buffer->line_max-1, buffer->line_off); + buffer->force_redraw = 0; + buffer->last_line_off = buffer->line_off; + if (TAILQ_EMPTY(&buffer->head)) - return; + goto end; l = 0; vl = nth_line(buffer, buffer->line_off); @@ -1535,6 +1548,7 @@ redraw_window(WINDOW *win, int height, struct buffer * break; } +end: wmove(win, buffer->curs_y, buffer->curs_x); }