diff options
author | Luuk van Baal <luukvbaal@gmail.com> | 2023-03-08 12:36:03 +0100 |
---|---|---|
committer | Luuk van Baal <luukvbaal@gmail.com> | 2023-03-08 12:36:03 +0100 |
commit | fe11079721084b3638ae3d8e5266f95d52028fb7 (patch) | |
tree | e7f749d6c7711dd46bbb698815167b7d1c92d7fa /src/nvim/drawscreen.c | |
parent | 1fb585a9db32ddfa563328a4ffb18b6f1e1dec1e (diff) | |
download | rneovim-fe11079721084b3638ae3d8e5266f95d52028fb7.tar.gz rneovim-fe11079721084b3638ae3d8e5266f95d52028fb7.tar.bz2 rneovim-fe11079721084b3638ae3d8e5266f95d52028fb7.zip |
perf(statusline): UI elements are always redrawn on K_EVENT
Problem: 'statusline'-format UI elements are redrawn on each K_EVENT.
Solution: Only redraw UI elements when something relevant has changed.
Diffstat (limited to 'src/nvim/drawscreen.c')
-rw-r--r-- | src/nvim/drawscreen.c | 64 |
1 files changed, 45 insertions, 19 deletions
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 0ac5220599..384dbf82f9 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -92,6 +92,7 @@ #include "nvim/profile.h" #include "nvim/regexp.h" #include "nvim/screen.h" +#include "nvim/state.h" #include "nvim/statusline.h" #include "nvim/syntax.h" #include "nvim/terminal.h" @@ -733,28 +734,53 @@ void show_cursor_info(bool always) return; } - win_check_ns_hl(curwin); - if ((*p_stl != NUL || *curwin->w_p_stl != NUL) - && (curwin->w_status_height || global_stl_height())) { - redraw_custom_statusline(curwin); - } else { - win_redr_ruler(curwin, always); - } - if (*p_wbr != NUL || *curwin->w_p_wbr != NUL) { - win_redr_winbar(curwin); - } + int state = get_real_state(); + int empty_line = (State & MODE_INSERT) == 0 + && *ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false) == NUL; + + // Only draw when something changed. + validate_virtcol_win(curwin); + if (always + || curwin->w_cursor.lnum != curwin->w_stl_cursor.lnum + || curwin->w_cursor.col != curwin->w_stl_cursor.col + || curwin->w_virtcol != curwin->w_stl_virtcol + || curwin->w_cursor.coladd != curwin->w_stl_cursor.coladd + || curwin->w_topline != curwin->w_stl_topline + || curwin->w_buffer->b_ml.ml_line_count != curwin->w_stl_line_count + || curwin->w_topfill != curwin->w_stl_topfill + || empty_line != curwin->w_stl_empty + || state != curwin->w_stl_state) { + win_check_ns_hl(curwin); + if ((*p_stl != NUL || *curwin->w_p_stl != NUL) + && (curwin->w_status_height || global_stl_height())) { + redraw_custom_statusline(curwin); + } else { + win_redr_ruler(curwin); + } + if (*p_wbr != NUL || *curwin->w_p_wbr != NUL) { + win_redr_winbar(curwin); + } - if (need_maketitle - || (p_icon && (stl_syntax & STL_IN_ICON)) - || (p_title && (stl_syntax & STL_IN_TITLE))) { - maketitle(); - } + if (need_maketitle + || (p_icon && (stl_syntax & STL_IN_ICON)) + || (p_title && (stl_syntax & STL_IN_TITLE))) { + maketitle(); + } - win_check_ns_hl(NULL); - // Redraw the tab pages line if needed. - if (redraw_tabline) { - draw_tabline(); + win_check_ns_hl(NULL); + // Redraw the tab pages line if needed. + if (redraw_tabline) { + draw_tabline(); + } } + + curwin->w_stl_cursor = curwin->w_cursor; + curwin->w_stl_virtcol = curwin->w_virtcol; + curwin->w_stl_empty = (char)empty_line; + curwin->w_stl_topline = curwin->w_topline; + curwin->w_stl_line_count = curwin->w_buffer->b_ml.ml_line_count; + curwin->w_stl_topfill = curwin->w_topfill; + curwin->w_stl_state = state; } static void redraw_win_signcol(win_T *wp) |