From 543e0256c19f397921a332e06b423215fd9aecb5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Nov 2023 15:51:05 +0800 Subject: build: don't define FUNC_ATTR_* as empty in headers (#26317) FUNC_ATTR_* should only be used in .c files with generated headers. Defining FUNC_ATTR_* as empty in headers causes misuses of them to be silently ignored. Instead don't define them by default, and only define them as empty after a .c file has included its generated header. --- src/nvim/diff.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/diff.c') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 0b7f6f266b..6578a1121c 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -32,7 +32,6 @@ #include "nvim/extmark.h" #include "nvim/fileio.h" #include "nvim/fold.h" -#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/gettext.h" #include "nvim/globals.h" -- cgit From 6346987601a28b00564295ee8be0a8b00d9ff911 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Thu, 7 Dec 2023 23:46:57 +0600 Subject: refactor(options): reduce `findoption()` usage Problem: Many places in the code use `findoption()` to access an option using its name, even if the option index is available. This is very slow because it requires looping through the options array over and over. Solution: Use option index instead of name wherever possible. Also introduce an `OptIndex` enum which contains the index for every option as enum constants, this eliminates the need to pass static option names as strings. --- src/nvim/diff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/diff.c') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 6578a1121c..483182dc25 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1389,7 +1389,7 @@ static void set_diff_option(win_T *wp, bool value) curwin = wp; curbuf = curwin->w_buffer; curbuf->b_ro_locked++; - set_option_value_give_err("diff", BOOLEAN_OPTVAL(value), OPT_LOCAL); + set_option_value_give_err(kOptDiff, BOOLEAN_OPTVAL(value), OPT_LOCAL); curbuf->b_ro_locked--; curwin = old_curwin; curbuf = curwin->w_buffer; @@ -1430,7 +1430,7 @@ void diff_win_options(win_T *wp, int addbuf) } wp->w_p_fdm_save = xstrdup(wp->w_p_fdm); } - set_string_option_direct_in_win(wp, "fdm", -1, "diff", OPT_LOCAL | OPT_FREE, 0); + set_string_option_direct_in_win(wp, kOptFoldmethod, "diff", OPT_LOCAL | OPT_FREE, 0); if (!wp->w_p_diff) { wp->w_p_fen_save = wp->w_p_fen; -- cgit From 7f6b775b45de5011ff1c44e63e57551566d80704 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 16 Dec 2023 22:14:28 +0100 Subject: refactor: use `bool` to represent boolean values --- src/nvim/diff.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/diff.c') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 483182dc25..765cbdadd2 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -59,7 +59,7 @@ #include "nvim/window.h" #include "xdiff/xdiff.h" -static int diff_busy = false; // using diff structs, don't change them +static bool diff_busy = false; // using diff structs, don't change them static bool diff_need_update = false; // ex_diffupdate needs to be called // Flags obtained from the 'diffopt' option @@ -384,7 +384,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T } dp->df_lnum[idx] += amount_after; } else { - int check_unchanged = false; + bool check_unchanged = false; // 2. 3. 4. 5.: inserted/deleted lines touching this diff. if (deleted > 0) { @@ -1003,7 +1003,7 @@ theend: static int check_external_diff(diffio_T *diffio) { // May try twice, first with "-a" and then without. - int io_error = false; + bool io_error = false; TriState ok = kFalse; while (true) { ok = kFalse; @@ -1472,7 +1472,7 @@ void diff_win_options(win_T *wp, int addbuf) /// @param eap void ex_diffoff(exarg_T *eap) { - int diffwin = false; + bool diffwin = false; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (eap->forceit ? wp->w_p_diff : (wp == curwin)) { @@ -2155,12 +2155,12 @@ int diff_check_with_linestatus(win_T *wp, linenr_T lnum, int *linestatus) } if (lnum < dp->df_lnum[idx] + dp->df_count[idx]) { - int zero = false; + bool zero = false; // Changed or inserted line. If the other buffers have a count of // zero, the lines were inserted. If the other buffers have the same // count, check if the lines are identical. - int cmp = false; + bool cmp = false; for (int i = 0; i < DB_COUNT; i++) { if ((i != idx) && (curtab->tp_diffbuf[i] != NULL)) { @@ -2195,7 +2195,7 @@ int diff_check_with_linestatus(win_T *wp, linenr_T lnum, int *linestatus) // the difference. Can't remove the entry here, we might be halfway // through updating the window. Just report the text as unchanged. // Other windows might still show the change though. - if (zero == false) { + if (!zero) { return 0; } return -2; @@ -2845,7 +2845,7 @@ void ex_diffgetput(exarg_T *eap) } if (*eap->arg == NUL) { - int found_not_ma = false; + bool found_not_ma = false; // No argument: Find the other buffer in the list of diff buffers. for (idx_other = 0; idx_other < DB_COUNT; idx_other++) { if ((curtab->tp_diffbuf[idx_other] != curbuf) -- cgit From c89292fcb7f2ebf06efb7c1d00c28f34c6f68fec Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 28 Dec 2023 13:42:24 +0100 Subject: refactor: follow style guide --- src/nvim/diff.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/diff.c') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 765cbdadd2..3e62555fac 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1012,7 +1012,7 @@ static int check_external_diff(diffio_T *diffio) if (fd == NULL) { io_error = true; } else { - if (fwrite("line1\n", (size_t)6, (size_t)1, fd) != 1) { + if (fwrite("line1\n", 6, 1, fd) != 1) { io_error = true; } fclose(fd); @@ -1021,7 +1021,7 @@ static int check_external_diff(diffio_T *diffio) if (fd == NULL) { io_error = true; } else { - if (fwrite("line2\n", (size_t)6, (size_t)1, fd) != 1) { + if (fwrite("line2\n", 6, 1, fd) != 1) { io_error = true; } fclose(fd); @@ -1166,9 +1166,9 @@ static int diff_file(diffio_T *dio) tmp_orig, tmp_new); append_redir(cmd, len, p_srr, tmp_diff); block_autocmds(); // Avoid ShellCmdPost stuff - (void)call_shell(cmd, - kShellOptFilter | kShellOptSilent | kShellOptDoOut, - NULL); + call_shell(cmd, + kShellOptFilter | kShellOptSilent | kShellOptDoOut, + NULL); unblock_autocmds(); xfree(cmd); return OK; @@ -1250,7 +1250,7 @@ void ex_diffpatch(exarg_T *eap) vim_snprintf(buf, buflen, "patch -o %s %s < %s", tmp_new, tmp_orig, esc_name); block_autocmds(); // Avoid ShellCmdPost stuff - (void)call_shell(buf, kShellOptFilter, NULL); + call_shell(buf, kShellOptFilter, NULL); unblock_autocmds(); } @@ -1398,7 +1398,7 @@ static void set_diff_option(win_T *wp, bool value) /// Set options in window "wp" for diff mode. /// /// @param addbuf Add buffer to diff. -void diff_win_options(win_T *wp, int addbuf) +void diff_win_options(win_T *wp, bool addbuf) { win_T *old_curwin = curwin; @@ -1888,7 +1888,7 @@ static void count_filler_lines_and_topline(int *curlinenum_to, int *linesfiller, { const diff_T *curdif = thistopdiff; int ch_virtual_lines = 0; - int isfiller = 0; + bool isfiller = false; while (virtual_lines_passed > 0) { if (ch_virtual_lines) { virtual_lines_passed--; @@ -1901,7 +1901,7 @@ static void count_filler_lines_and_topline(int *curlinenum_to, int *linesfiller, } else { (*linesfiller) = 0; ch_virtual_lines = get_max_diff_length(curdif); - isfiller = (curdif->df_count[toidx] ? 0 : 1); + isfiller = (curdif->df_count[toidx] ? false : true); if (isfiller) { while (curdif && curdif->df_next && curdif->df_lnum[toidx] == curdif->df_next->df_lnum[toidx] @@ -2444,8 +2444,8 @@ void diff_set_topline(win_T *fromwin, win_T *towin) changed_line_abv_curs_win(towin); check_topfill(towin, false); - (void)hasFoldingWin(towin, towin->w_topline, &towin->w_topline, - NULL, true, NULL); + hasFoldingWin(towin, towin->w_topline, &towin->w_topline, + NULL, true, NULL); } /// This is called when 'diffopt' is changed. -- cgit From 10f36af84d4ccb0b626cd6c79c6ba2f2735a56fd Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 10 Jan 2024 04:15:22 +0600 Subject: refactor(options): remove `OPT_FREE` (#26963) Problem: `OPT_FREE` macro doesn't seem to do anything as `P_ALLOCED` already handles allocations. Solution: Remove `OPT_FREE`. --- src/nvim/diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/diff.c') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 3e62555fac..f8aed21556 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1430,7 +1430,7 @@ void diff_win_options(win_T *wp, bool addbuf) } wp->w_p_fdm_save = xstrdup(wp->w_p_fdm); } - set_string_option_direct_in_win(wp, kOptFoldmethod, "diff", OPT_LOCAL | OPT_FREE, 0); + set_string_option_direct_in_win(wp, kOptFoldmethod, "diff", OPT_LOCAL, 0); if (!wp->w_p_diff) { wp->w_p_fen_save = wp->w_p_fen; -- cgit From 1813661a6197c76ea6621284570aca1d56597099 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 4 Jan 2024 15:38:16 +0100 Subject: refactor(IWYU): fix headers Remove `export` pramgas from defs headers as it causes IWYU to believe that the definitions from the defs headers comes from main header, which is not what we really want. --- src/nvim/diff.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/nvim/diff.c') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index f8aed21556..2b3010e063 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -18,6 +18,7 @@ #include "auto/config.h" #include "nvim/ascii_defs.h" #include "nvim/autocmd.h" +#include "nvim/autocmd_defs.h" #include "nvim/buffer.h" #include "nvim/bufwrite.h" #include "nvim/change.h" @@ -30,24 +31,30 @@ #include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/extmark.h" +#include "nvim/extmark_defs.h" #include "nvim/fileio.h" #include "nvim/fold.h" #include "nvim/garray.h" -#include "nvim/gettext.h" +#include "nvim/garray_defs.h" +#include "nvim/gettext_defs.h" #include "nvim/globals.h" #include "nvim/linematch.h" #include "nvim/mark.h" #include "nvim/mbyte.h" +#include "nvim/mbyte_defs.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/move.h" #include "nvim/normal.h" #include "nvim/option.h" +#include "nvim/option_defs.h" #include "nvim/option_vars.h" #include "nvim/optionstr.h" #include "nvim/os/fs.h" +#include "nvim/os/fs_defs.h" #include "nvim/os/os.h" +#include "nvim/os/os_defs.h" #include "nvim/os/shell.h" #include "nvim/path.h" #include "nvim/pos_defs.h" -- cgit