comparison src/undo.c @ 34365:8303936dbd64 v9.1.0113

patch 9.1.0113: duplicate code when cleaning undo stack Commit: https://github.com/vim/vim/commit/9071ed8107244e0c56a16b77d1c28e975cb21dd2 Author: Christian Brabandt <cb@256bit.org> 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 <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 15 Feb 2024 20:30:05 +0100
parents b80d18055370
children
comparison
equal deleted inserted replaced
34364:f5d16cbbf2d5 34365:8303936dbd64
121 static void unserialize_pos(bufinfo_T *bi, pos_T *pos); 121 static void unserialize_pos(bufinfo_T *bi, pos_T *pos);
122 static void serialize_visualinfo(bufinfo_T *bi, visualinfo_T *info); 122 static void serialize_visualinfo(bufinfo_T *bi, visualinfo_T *info);
123 static void unserialize_visualinfo(bufinfo_T *bi, visualinfo_T *info); 123 static void unserialize_visualinfo(bufinfo_T *bi, visualinfo_T *info);
124 #endif 124 #endif
125 static void u_saveline(linenr_T lnum); 125 static void u_saveline(linenr_T lnum);
126 static void u_blockfree(buf_T *buf);
126 127
127 #define U_ALLOC_LINE(size) lalloc(size, FALSE) 128 #define U_ALLOC_LINE(size) lalloc(size, FALSE)
128 129
129 // used in undo_end() to report number of added and deleted lines 130 // used in undo_end() to report number of added and deleted lines
130 static long u_newcount, u_oldcount; 131 static long u_newcount, u_oldcount;
3470 } 3471 }
3471 3472
3472 /* 3473 /*
3473 * invalidate the undo buffer; called when storage has already been released 3474 * invalidate the undo buffer; called when storage has already been released
3474 */ 3475 */
3475 void 3476 static void
3476 u_clearall(buf_T *buf) 3477 u_clearall(buf_T *buf)
3477 { 3478 {
3478 buf->b_u_newhead = buf->b_u_oldhead = buf->b_u_curhead = NULL; 3479 buf->b_u_newhead = buf->b_u_oldhead = buf->b_u_curhead = NULL;
3479 buf->b_u_synced = TRUE; 3480 buf->b_u_synced = TRUE;
3480 buf->b_u_numhead = 0; 3481 buf->b_u_numhead = 0;
3481 buf->b_u_line_ptr.ul_line = NULL; 3482 buf->b_u_line_ptr.ul_line = NULL;
3482 buf->b_u_line_ptr.ul_len = 0; 3483 buf->b_u_line_ptr.ul_len = 0;
3483 buf->b_u_line_lnum = 0; 3484 buf->b_u_line_lnum = 0;
3484 } 3485 }
3486
3487 /*
3488 * Free all allocated memory blocks for the buffer 'buf'.
3489 */
3490 static void
3491 u_blockfree(buf_T *buf)
3492 {
3493 while (buf->b_u_oldhead != NULL)
3494 u_freeheader(buf, buf->b_u_oldhead, NULL);
3495 vim_free(buf->b_u_line_ptr.ul_line);
3496 }
3497
3498 /*
3499 * Free all allocated memory blocks for the buffer 'buf'.
3500 * and invalidate the undo buffer
3501 */
3502 void
3503 u_clearallandblockfree(buf_T *buf)
3504 {
3505 u_blockfree(buf);
3506 u_clearall(buf);
3507 }
3508
3509
3485 3510
3486 /* 3511 /*
3487 * Save the line "lnum" for the "U" command. 3512 * Save the line "lnum" for the "U" command.
3488 */ 3513 */
3489 static void 3514 static void
3561 curwin->w_cursor.lnum = curbuf->b_u_line_lnum; 3586 curwin->w_cursor.lnum = curbuf->b_u_line_lnum;
3562 check_cursor_col(); 3587 check_cursor_col();
3563 } 3588 }
3564 3589
3565 /* 3590 /*
3566 * Free all allocated memory blocks for the buffer 'buf'.
3567 */
3568 void
3569 u_blockfree(buf_T *buf)
3570 {
3571 while (buf->b_u_oldhead != NULL)
3572 u_freeheader(buf, buf->b_u_oldhead, NULL);
3573 vim_free(buf->b_u_line_ptr.ul_line);
3574 }
3575
3576 /*
3577 * Check if the 'modified' flag is set, or 'ff' has changed (only need to 3591 * Check if the 'modified' flag is set, or 'ff' has changed (only need to
3578 * check the first character, because it can only be "dos", "unix" or "mac"). 3592 * check the first character, because it can only be "dos", "unix" or "mac").
3579 * "nofile" and "scratch" type buffers are considered to always be unchanged. 3593 * "nofile" and "scratch" type buffers are considered to always be unchanged.
3580 * Also considers a buffer changed when a terminal window contains a running 3594 * Also considers a buffer changed when a terminal window contains a running
3581 * job. 3595 * job.