patch 9.1.0704: inserting with a count is inefficient

Commit: 
https://github.com/vim/vim/commit/09b80d23cfae24fa13ef4f52b0ec90625839a6ab
Author: Ken Takata <ken...@csc.jp>
Date:   Sat Aug 31 16:35:06 2024 +0200

    patch 9.1.0704: inserting with a count is inefficient
    
    Problem:  inserting with a count is inefficient
    Solution: Disable calculation of the cursor position and topline, if a
              count has been used (Ken Takata)
    
    Optimize insertion when using :normal 10000ix.
    
    This patch optimizes the insertion with a large count (e.g. `:normal
    10000ix`).
    
    It seems that calculation of the cursor position for a long line is slow
    and it takes O(n^2). Disable the calculation if not needed.
    
    Before:
    ```
    $ time ./vim --clean -c 'normal 10000ix' -cq!
    real    0m1.879s
    user    0m1.328s
    sys     0m0.139s
    
    $ time ./vim --clean -c 'normal 20000ix' -cq!
    real    0m5.574s
    user    0m5.421s
    sys     0m0.093s
    
    $ time ./vim --clean -c 'normal 40000ix' -cq!
    real    0m23.588s
    user    0m23.187s
    sys     0m0.140s
    ```
    
    After:
    ```
    $ time ./vim --clean -c 'normal 10000ix' -cq!
    real    0m0.187s
    user    0m0.046s
    sys     0m0.093s
    
    $ time ./vim --clean -c 'normal 20000ix' -cq!
    real    0m0.217s
    user    0m0.046s
    sys     0m0.108s
    
    $ time ./vim --clean -c 'normal 40000ix' -cq!
    real    0m0.278s
    user    0m0.093s
    sys     0m0.140s
    
    $ time ./vim --clean -c 'normal 80000ix' -cq!
    real    0m0.494s
    user    0m0.311s
    sys     0m0.140s
    
    $ time ./vim --clean -c 'normal 160000ix' -cq!
    real    0m1.302s
    user    0m1.140s
    sys     0m0.094s
    ```
    
    closes: #15588
    
    Signed-off-by: K.Takata <ken...@csc.jp>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/edit.c b/src/edit.c
index 8a37a6169..e1f30c7c2 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -512,6 +512,7 @@ edit(
 #ifdef FEAT_DIFF
                && curwin->w_topfill == old_topfill
 #endif
+               && count <= 1
                )
        {
            mincol = curwin->w_wcol;
@@ -549,11 +550,13 @@ edit(
        }
 
        // May need to adjust w_topline to show the cursor.
-       update_topline();
+       if (count <= 1)
+           update_topline();
 
        did_backspace = FALSE;
 
-       validate_cursor();              // may set must_redraw
+       if (count <= 1)
+           validate_cursor();          // may set must_redraw
 
        /*
         * Redraw the display when no characters are waiting.
@@ -566,7 +569,8 @@ edit(
 
        if (curwin->w_p_crb)
            do_check_cursorbind();
-       update_curswant();
+       if (count <= 1)
+           update_curswant();
        old_topline = curwin->w_topline;
 #ifdef FEAT_DIFF
        old_topfill = curwin->w_topfill;
diff --git a/src/version.c b/src/version.c
index 3c30cbdb4..44137b736 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    704,
 /**/
     703,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1skPLb-002Z5a-96%40256bit.org.

Raspunde prin e-mail lui