From bb6190bec5f18c1f9e2c1d29ef1f7cf7912ea625 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 1 Jun 2024 08:19:41 -0700 Subject: refactor: move shared messages to errors.h #26214 --- src/nvim/bufwrite.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/bufwrite.c') diff --git a/src/nvim/bufwrite.c b/src/nvim/bufwrite.c index 27de03954a..6fbcb2dbb8 100644 --- a/src/nvim/bufwrite.c +++ b/src/nvim/bufwrite.c @@ -18,6 +18,7 @@ #include "nvim/bufwrite.h" #include "nvim/change.h" #include "nvim/drawscreen.h" +#include "nvim/errors.h" #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds.h" -- cgit From a056cc1300ef062d4f757873a647b20b8331ab03 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 10 Jun 2024 06:37:56 +0800 Subject: vim-patch:9.1.0472: Inconsistencies between functions for option flags (#29262) Problem: Inconsistencies between functions for option flags. Solution: Consistently use "unsigned int" as return type and rename get_bkc_value() to get_bkc_flags() (zeertzjq). closes: vim/vim#14925 https://github.com/vim/vim/commit/aa925eeb97bd294d4a5253a3194949a37cbc8365 --- src/nvim/bufwrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/bufwrite.c') diff --git a/src/nvim/bufwrite.c b/src/nvim/bufwrite.c index 6fbcb2dbb8..5522ab1ca3 100644 --- a/src/nvim/bufwrite.c +++ b/src/nvim/bufwrite.c @@ -1066,7 +1066,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en bool whole = (start == 1 && end == buf->b_ml.ml_line_count); bool write_undo_file = false; context_sha256_T sha_ctx; - unsigned bkc = get_bkc_value(buf); + unsigned bkc = get_bkc_flags(buf); if (fname == NULL || *fname == NUL) { // safety check return FAIL; -- cgit From 4bb6cd4c2d34d9ddde1999a2b8cb366dd9fd3e4a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 17 Jul 2024 09:48:39 +0800 Subject: vim-patch:8.2.3543: swapname has double slash when 'directory' ends in it Problem: Swapname has double slash when 'directory' ends in double slash. (Shane Smith) Solution: Remove the superfluous slash. (closes vim/vim#8876) https://github.com/vim/vim/commit/8b0e62c93b6dad5ec5b2c7558d4f7b78c46216d2 Co-authored-by: Bram Moolenaar --- src/nvim/bufwrite.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/nvim/bufwrite.c') diff --git a/src/nvim/bufwrite.c b/src/nvim/bufwrite.c index 5522ab1ca3..546c5e20f2 100644 --- a/src/nvim/bufwrite.c +++ b/src/nvim/bufwrite.c @@ -822,9 +822,6 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ","); char *p = IObuff + dir_len; bool trailing_pathseps = after_pathsep(IObuff, p) && p[-1] == p[-2]; - if (trailing_pathseps) { - IObuff[dir_len - 2] = NUL; - } if (*dirp == NUL && !os_isdir(IObuff)) { int ret; char *failed_dir; @@ -964,9 +961,6 @@ nobackup: size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ","); char *p = IObuff + dir_len; bool trailing_pathseps = after_pathsep(IObuff, p) && p[-1] == p[-2]; - if (trailing_pathseps) { - IObuff[dir_len - 2] = NUL; - } if (*dirp == NUL && !os_isdir(IObuff)) { int ret; char *failed_dir; -- cgit From 114d1e7b43b8e1bc4143d1bc963cf90c248be059 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 26 Jul 2024 07:19:05 +0800 Subject: vim-patch:9.1.0615: Unnecessary STRLEN() in make_percent_swname() Problem: Unnecessary STRLEN() in make_percent_swname() Solution: Pass the end of "dir" to make_percent_swname() (zeertzjq) closes: vim/vim#15340 https://github.com/vim/vim/commit/242667ae142d9862a7bace82c58cb11c79fdab7a --- src/nvim/bufwrite.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/nvim/bufwrite.c') diff --git a/src/nvim/bufwrite.c b/src/nvim/bufwrite.c index 546c5e20f2..9f6eb8c9e8 100644 --- a/src/nvim/bufwrite.c +++ b/src/nvim/bufwrite.c @@ -821,7 +821,6 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o // Isolate one directory name, using an entry in 'bdir'. size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ","); char *p = IObuff + dir_len; - bool trailing_pathseps = after_pathsep(IObuff, p) && p[-1] == p[-2]; if (*dirp == NUL && !os_isdir(IObuff)) { int ret; char *failed_dir; @@ -831,9 +830,9 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o xfree(failed_dir); } } - if (trailing_pathseps) { + if (after_pathsep(IObuff, p) && p[-1] == p[-2]) { // Ends with '//', Use Full path - if ((p = make_percent_swname(IObuff, fname)) + if ((p = make_percent_swname(IObuff, p, fname)) != NULL) { *backupp = modname(p, backup_ext, no_prepend_dot); xfree(p); @@ -960,7 +959,6 @@ nobackup: // Isolate one directory name and make the backup file name. size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ","); char *p = IObuff + dir_len; - bool trailing_pathseps = after_pathsep(IObuff, p) && p[-1] == p[-2]; if (*dirp == NUL && !os_isdir(IObuff)) { int ret; char *failed_dir; @@ -970,9 +968,9 @@ nobackup: xfree(failed_dir); } } - if (trailing_pathseps) { + if (after_pathsep(IObuff, p) && p[-1] == p[-2]) { // path ends with '//', use full path - if ((p = make_percent_swname(IObuff, fname)) + if ((p = make_percent_swname(IObuff, p, fname)) != NULL) { *backupp = modname(p, backup_ext, no_prepend_dot); xfree(p); -- cgit From d1bd3d643e5846eee7343ba1a12bdcbbc8cee7b0 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 19 Jul 2024 11:00:13 +0100 Subject: refactor: collapse statements in single assignments Problem: Variables are often assigned multiple places in common patterns. Solution: Replace these common patterns with different patterns that reduce the number of assignments. Use `MAX` and `MIN`: ```c if (x < y) { x = y; } // --> x = MAX(x, y); ``` ```c if (x > y) { x = y; } // --> x = MIN(x, y); ``` Use ternary: ```c int a; if (cond) { a = b; } els { a = c; } // --> int a = cond ? b : c; ``` --- src/nvim/bufwrite.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'src/nvim/bufwrite.c') diff --git a/src/nvim/bufwrite.c b/src/nvim/bufwrite.c index 9f6eb8c9e8..fa0a55e7b6 100644 --- a/src/nvim/bufwrite.c +++ b/src/nvim/bufwrite.c @@ -261,11 +261,8 @@ static int buf_write_convert(struct bw_info *ip, char **bufp, int *lenp) ip->bw_restlen += *lenp; break; } - if (n > 1) { - c = (unsigned)utf_ptr2char((char *)ip->bw_rest); - } else { - c = ip->bw_rest[0]; - } + c = (n > 1) ? (unsigned)utf_ptr2char((char *)ip->bw_rest) + : ip->bw_rest[0]; if (n >= ip->bw_restlen) { n -= ip->bw_restlen; ip->bw_restlen = 0; @@ -289,11 +286,8 @@ static int buf_write_convert(struct bw_info *ip, char **bufp, int *lenp) (size_t)ip->bw_restlen); break; } - if (n > 1) { - c = (unsigned)utf_ptr2char(*bufp + wlen); - } else { - c = (uint8_t)(*bufp)[wlen]; - } + c = n > 1 ? (unsigned)utf_ptr2char(*bufp + wlen) + : (uint8_t)(*bufp)[wlen]; } if (ucs2bytes(c, &p, flags) && !ip->bw_conv_error) { @@ -876,9 +870,7 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o // Change one character, just before the extension. // char *wp = *backupp + strlen(*backupp) - 1 - strlen(backup_ext); - if (wp < *backupp) { // empty file name ??? - wp = *backupp; - } + wp = MAX(wp, *backupp); // empty file name ??? *wp = 'z'; while (*wp > 'a' && os_fileinfo(*backupp, &file_info_new)) { (*wp)--; @@ -993,9 +985,7 @@ nobackup: // Change one character, just before the extension. if (!p_bk && os_path_exists(*backupp)) { p = *backupp + strlen(*backupp) - 1 - strlen(backup_ext); - if (p < *backupp) { // empty file name ??? - p = *backupp; - } + p = MAX(p, *backupp); // empty file name ??? *p = 'z'; while (*p > 'a' && os_path_exists(*backupp)) { (*p)--; @@ -1255,9 +1245,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en status_redraw_all(); // redraw status lines later } - if (end > buf->b_ml.ml_line_count) { - end = buf->b_ml.ml_line_count; - } + end = MIN(end, buf->b_ml.ml_line_count); if (buf->b_ml.ml_flags & ML_EMPTY) { start = end + 1; } -- cgit