Mercurial > vim
diff src/diff.c @ 19888:435726a03481 v8.2.0500
patch 8.2.0500: using the same loop in many places
Commit: https://github.com/vim/vim/commit/aeea72151c31d686bcbb7b06d895006d7363585c
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Apr 2 18:50:46 2020 +0200
patch 8.2.0500: using the same loop in many places
Problem: Using the same loop in many places.
Solution: Define more FOR_ALL macros. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5339)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 02 Apr 2020 19:00:05 +0200 |
parents | 3a68dc2a1bc1 |
children | aadd1cae2ff5 |
line wrap: on
line diff
--- a/src/diff.c +++ b/src/diff.c @@ -90,6 +90,9 @@ static int parse_diff_ed(char_u *line, l static int parse_diff_unified(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new, long *count_new); static int xdiff_out(void *priv, mmbuffer_t *mb, int nbuf); +#define FOR_ALL_DIFFBLOCKS_IN_TAB(tp, dp) \ + for ((dp) = (tp)->tp_first_diff; (dp) != NULL; (dp) = (dp)->df_next) + /* * Called when deleting or unloading a buffer: No longer make a diff with it. */ @@ -1857,7 +1860,7 @@ diff_check(win_T *wp, linenr_T lnum) #endif // search for a change that includes "lnum" in the list of diffblocks. - for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) + FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) break; if (dp == NULL || lnum < dp->df_lnum[idx]) @@ -2069,7 +2072,7 @@ diff_set_topline(win_T *fromwin, win_T * towin->w_topfill = 0; // search for a change that includes "lnum" in the list of diffblocks. - for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) + FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) break; if (dp == NULL) @@ -2374,7 +2377,7 @@ diff_find_change( } // search for a change that includes "lnum" in the list of diffblocks. - for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) + FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) break; if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL) @@ -2508,7 +2511,7 @@ diff_infold(win_T *wp, linenr_T lnum) if (curtab->tp_first_diff == NULL) return TRUE; - for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) + FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) { // If this change is below the line there can't be any further match. if (dp->df_lnum[idx] - diff_context > lnum) @@ -3001,7 +3004,7 @@ diff_get_corresponding_line_int( if (curtab->tp_first_diff == NULL) // no diffs today return lnum1; - for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) + FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) { if (dp->df_lnum[idx1] > lnum1) return lnum1 - baseline; @@ -3070,7 +3073,7 @@ diff_lnum_win(linenr_T lnum, win_T *wp) ex_diffupdate(NULL); // update after a big change // search for a change that includes "lnum" in the list of diffblocks. - for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) + FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) break;