]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0113: duplicate code when cleaning undo stack v9.1.0113
authorChristian Brabandt <cb@256bit.org>
Thu, 15 Feb 2024 19:17:37 +0000 (20:17 +0100)
committerChristian Brabandt <cb@256bit.org>
Thu, 15 Feb 2024 19:17:37 +0000 (20:17 +0100)
Problem:  duplicate code when cleaning undo stack
Solution: refactor undo cleanup into a single public function

related: #13928

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/buffer.c
src/fileio.c
src/netbeans.c
src/proto/undo.pro
src/quickfix.c
src/undo.c
src/version.c

index 62c396a5317e90613a42c774065fad83055da379..4a39329c5c602617e62e524b99569b71390545e1 100644 (file)
@@ -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
index 180fe3906c2305c6bc371544643056af575b2036..d293d713d3610d7c3c758cacebfa6985ab7bae6f 100644 (file)
@@ -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.
index ebdf3a44fab316c55f65f791cce333f0fbae0563..d542b58868872df5cb210689d665201998ccd65c 100644 (file)
@@ -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
index 851d281f3046a74824c7f24e94daf69ef396b095..619ad702345335045f8ec3e3a539e306e0450ad3 100644 (file)
@@ -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);
index 3e2d3dfcc0a70902c4b5b38efef7970237b66285..d8bcc1232afd8549caf5dc2c9960579cb18e782e 100644 (file)
@@ -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
index b2c4e9a56862bf1e65c95cfee83db56b63ebdfd2..1cd8912823a0d1efad42797e712507534a76e3cd 100644 (file)
@@ -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").
index d23c9ce5af34b0249b2e241122513c20d127d191..25fff8382db7c516ba6e00a77024f63c9f1a956c 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    113,
 /**/
     112,
 /**/