]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1385: inefficient loop for 'nosmoothscroll' scrolling v9.1.1385
authorLuuk van Baal <luukvbaal@gmail.com>
Mon, 12 May 2025 18:45:41 +0000 (20:45 +0200)
committerChristian Brabandt <cb@256bit.org>
Mon, 12 May 2025 18:47:00 +0000 (20:47 +0200)
Problem:  Loop that ensures "w_skipcol" is zero with 'nosmoothscroll'
  for (half)-page scrolling is inefficient.
Solution: Calculate the required "count" instead of looping until
  "w_skipcol" is zero (Luuk van Baal).

fixes: #17301
closes: #17306

Signed-off-by: Luuk van Baal <luukvbaal@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/move.c
src/testdir/test_normal.vim
src/version.c

index f4bce40d7bceb6b48c11654ea9c82e46564cd3e6..1c1eddeef5c01f50709f19564666d37b8bf6175e 100644 (file)
@@ -3212,12 +3212,15 @@ static int scroll_with_sms(int dir, long count, long *curscount)
        // extra for scrolling backward so that consuming skipcol is symmetric.
        if (labs(curwin->w_topline - prev_topline) > (dir == BACKWARD))
            fixdir = dir * -1;
-       while (curwin->w_skipcol > 0
-           && curwin->w_topline < curbuf->b_ml.ml_line_count)
-       {
-           scroll_redraw(fixdir == FORWARD, 1);
-           *curscount += (fixdir == dir ? 1 : -1);
-       }
+
+       int width1 = curwin->w_width - curwin_col_off();
+       int width2 = width1 + curwin_col_off2();
+       count = 1 + (curwin->w_skipcol - width1) / width2;
+       if (fixdir == FORWARD)
+           count = 2 + (linetabsize_eol(curwin, curwin->w_topline)
+                                       - curwin->w_skipcol - width1) / width2;
+       scroll_redraw(fixdir == FORWARD, count);
+       *curscount += count * (fixdir == dir ? 1 : -1);
     }
     curwin->w_p_sms = prev_sms;
 
index aa24bceda5437616eed8f9a6b8107b4384b366b4..7f4f909645e5d41a64e0abef53a859eddd63fcdf 100644 (file)
@@ -4345,4 +4345,13 @@ func Test_scroll_longline_scrolloff()
   bwipe!
 endfunc
 
+" Benchmark test for Ctrl-F with 'nosmoothscroll'
+func Test_scroll_longline_benchmark()
+  call setline(1, ['foo'->repeat(20000)] + [''])
+  let start = reltime()
+  exe "normal! \<C-F>"
+  call assert_inrange(0, 0.1, reltimefloat(reltime(start)))
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab nofoldenable
index 55860d2d602fd819b79074094f12970eeac41817..a2cfb00f3273a3805a5ffe7274fde926775a3f8a 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1385,
 /**/
     1384,
 /**/