patch 9.1.0113: duplicate code when cleaning undo stack

Commit: 
https://github.com/vim/vim/commit/9071ed8107244e0c56a16b77d1c28e975cb21dd2
Author: Christian Brabandt <[email protected]>
Date:   Thu Feb 15 20:17:37 2024 +0100

    patch 9.1.0113: duplicate code when cleaning undo stack
    
    Problem:  duplicate code when cleaning undo stack
    Solution: refactor undo cleanup into a single public function
    
    related: #13928
    
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/buffer.c b/src/buffer.c
index 62c396a53..4a39329c5 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -919,10 +919,9 @@ buf_freeall(buf_T *buf, int flags)
     ml_close(buf, TRUE);           // close and delete the memline/memfile
     buf->b_ml.ml_line_count = 0;    // no lines in buffer
     if ((flags & BFA_KEEP_UNDO) == 0)
-    {
-       u_blockfree(buf);           // free the memory allocated for undo
-       u_clearall(buf);            // reset all undo information
-    }
+       // free the memory allocated for undo
+       // and reset all undo information
+       u_clearallandblockfree(buf);
 #ifdef FEAT_SYN_HL
     syntax_clear(&buf->b_s);       // reset syntax info
 #endif
diff --git a/src/fileio.c b/src/fileio.c
index 180fe3906..d293d713d 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4514,10 +4514,7 @@ buf_reload(buf_T *buf, int orig_mode, int reload_options)
                // Mark the buffer as unmodified and free undo info.
                unchanged(buf, TRUE, TRUE);
                if ((flags & READ_KEEP_UNDO) == 0)
-               {
-                   u_blockfree(buf);
-                   u_clearall(buf);
-               }
+                   u_clearallandblockfree(buf);
                else
                {
                    // Mark all undo states as changed.
diff --git a/src/netbeans.c b/src/netbeans.c
index ebdf3a44f..d542b5886 100644
--- a/src/netbeans.c
+++ b/src/netbeans.c
@@ -1285,8 +1285,7 @@ nb_do_cmd(
                netbeansFireChanges = oldFire;
                netbeansSuppressNoLines = oldSuppress;
 
-               u_blockfree(buf->bufp);
-               u_clearall(buf->bufp);
+               u_clearallandblockfree(buf->bufp);
            }
            nb_reply_nil(cmdno);
 // =====================================================================
@@ -1456,8 +1455,7 @@ nb_do_cmd(
                netbeansFireChanges = oldFire;
 
                // Undo info is invalid now...
-               u_blockfree(curbuf);
-               u_clearall(curbuf);
+               u_clearallandblockfree(curbuf);
            }
            vim_free(to_free);
            nb_reply_nil(cmdno); // or !error
diff --git a/src/proto/undo.pro b/src/proto/undo.pro
index 851d281f3..619ad7023 100644
--- a/src/proto/undo.pro
+++ b/src/proto/undo.pro
@@ -18,10 +18,9 @@ void ex_undojoin(exarg_T *eap);
 void u_unchanged(buf_T *buf);
 void u_find_first_changed(void);
 void u_update_save_nr(buf_T *buf);
-void u_clearall(buf_T *buf);
 void u_clearline(void);
 void u_undoline(void);
-void u_blockfree(buf_T *buf);
+void u_clearallandblockfree(buf_T *buf);
 int bufIsChanged(buf_T *buf);
 int anyBufIsChanged(void);
 int bufIsChangedNotTerm(buf_T *buf);
diff --git a/src/quickfix.c b/src/quickfix.c
index 3e2d3dfcc..d8bcc1232 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4839,8 +4839,7 @@ qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T 
*old_last, int qf_winid)
            (void)ml_delete((linenr_T)1);
 
        // Remove all undo information
-       u_blockfree(curbuf);
-       u_clearall(curbuf);
+       u_clearallandblockfree(curbuf);
     }
 
     // Check if there is anything to display
diff --git a/src/undo.c b/src/undo.c
index b2c4e9a56..1cd891282 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -123,6 +123,7 @@ static void serialize_visualinfo(bufinfo_T *bi, 
visualinfo_T *info);
 static void unserialize_visualinfo(bufinfo_T *bi, visualinfo_T *info);
 #endif
 static void u_saveline(linenr_T lnum);
+static void u_blockfree(buf_T *buf);
 
 #define U_ALLOC_LINE(size) lalloc(size, FALSE)
 
@@ -3472,7 +3473,7 @@ u_freeentry(u_entry_T *uep, long n)
 /*
  * invalidate the undo buffer; called when storage has already been released
  */
-    void
+    static void
 u_clearall(buf_T *buf)
 {
     buf->b_u_newhead = buf->b_u_oldhead = buf->b_u_curhead = NULL;
@@ -3483,6 +3484,30 @@ u_clearall(buf_T *buf)
     buf->b_u_line_lnum = 0;
 }
 
+/*
+ * Free all allocated memory blocks for the buffer 'buf'.
+ */
+    static void
+u_blockfree(buf_T *buf)
+{
+    while (buf->b_u_oldhead != NULL)
+       u_freeheader(buf, buf->b_u_oldhead, NULL);
+    vim_free(buf->b_u_line_ptr.ul_line);
+}
+
+/*
+ * Free all allocated memory blocks for the buffer 'buf'.
+ * and invalidate the undo buffer
+ */
+    void
+u_clearallandblockfree(buf_T *buf)
+{
+    u_blockfree(buf);
+    u_clearall(buf);
+}
+
+
+
 /*
  * Save the line "lnum" for the "U" command.
  */
@@ -3562,17 +3587,6 @@ u_undoline(void)
     check_cursor_col();
 }
 
-/*
- * Free all allocated memory blocks for the buffer 'buf'.
- */
-    void
-u_blockfree(buf_T *buf)
-{
-    while (buf->b_u_oldhead != NULL)
-       u_freeheader(buf, buf->b_u_oldhead, NULL);
-    vim_free(buf->b_u_line_ptr.ul_line);
-}
-
 /*
  * Check if the 'modified' flag is set, or 'ff' has changed (only need to
  * check the first character, because it can only be "dos", "unix" or "mac").
diff --git a/src/version.c b/src/version.c
index d23c9ce5a..25fff8382 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 */
+/**/
+    113,
 /**/
     112,
 /**/

-- 
-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rahQr-00GwUV-P4%40256bit.org.

Raspunde prin e-mail lui