comparison 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
comparison
equal deleted inserted replaced
19887:d03edd8c7e2f 19888:435726a03481
87 static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, int idx_new); 87 static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, int idx_new);
88 static diff_T *diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp); 88 static diff_T *diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp);
89 static int parse_diff_ed(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new, long *count_new); 89 static int parse_diff_ed(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new, long *count_new);
90 static int parse_diff_unified(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new, long *count_new); 90 static int parse_diff_unified(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new, long *count_new);
91 static int xdiff_out(void *priv, mmbuffer_t *mb, int nbuf); 91 static int xdiff_out(void *priv, mmbuffer_t *mb, int nbuf);
92
93 #define FOR_ALL_DIFFBLOCKS_IN_TAB(tp, dp) \
94 for ((dp) = (tp)->tp_first_diff; (dp) != NULL; (dp) = (dp)->df_next)
92 95
93 /* 96 /*
94 * Called when deleting or unloading a buffer: No longer make a diff with it. 97 * Called when deleting or unloading a buffer: No longer make a diff with it.
95 */ 98 */
96 void 99 void
1855 if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) 1858 if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL))
1856 return 0; 1859 return 0;
1857 #endif 1860 #endif
1858 1861
1859 // search for a change that includes "lnum" in the list of diffblocks. 1862 // search for a change that includes "lnum" in the list of diffblocks.
1860 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) 1863 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
1861 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) 1864 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx])
1862 break; 1865 break;
1863 if (dp == NULL || lnum < dp->df_lnum[idx]) 1866 if (dp == NULL || lnum < dp->df_lnum[idx])
1864 return 0; 1867 return 0;
1865 1868
2067 ex_diffupdate(NULL); // update after a big change 2070 ex_diffupdate(NULL); // update after a big change
2068 2071
2069 towin->w_topfill = 0; 2072 towin->w_topfill = 0;
2070 2073
2071 // search for a change that includes "lnum" in the list of diffblocks. 2074 // search for a change that includes "lnum" in the list of diffblocks.
2072 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) 2075 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
2073 if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) 2076 if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx])
2074 break; 2077 break;
2075 if (dp == NULL) 2078 if (dp == NULL)
2076 { 2079 {
2077 // After last change, compute topline relative to end of file; no 2080 // After last change, compute topline relative to end of file; no
2372 vim_free(line_org); 2375 vim_free(line_org);
2373 return FALSE; 2376 return FALSE;
2374 } 2377 }
2375 2378
2376 // search for a change that includes "lnum" in the list of diffblocks. 2379 // search for a change that includes "lnum" in the list of diffblocks.
2377 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) 2380 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
2378 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) 2381 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx])
2379 break; 2382 break;
2380 if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL) 2383 if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL)
2381 { 2384 {
2382 vim_free(line_org); 2385 vim_free(line_org);
2506 2509
2507 // Return if there are no diff blocks. All lines will be folded. 2510 // Return if there are no diff blocks. All lines will be folded.
2508 if (curtab->tp_first_diff == NULL) 2511 if (curtab->tp_first_diff == NULL)
2509 return TRUE; 2512 return TRUE;
2510 2513
2511 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) 2514 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
2512 { 2515 {
2513 // If this change is below the line there can't be any further match. 2516 // If this change is below the line there can't be any further match.
2514 if (dp->df_lnum[idx] - diff_context > lnum) 2517 if (dp->df_lnum[idx] - diff_context > lnum)
2515 break; 2518 break;
2516 // If this change ends before the line we have a match. 2519 // If this change ends before the line we have a match.
2999 ex_diffupdate(NULL); // update after a big change 3002 ex_diffupdate(NULL); // update after a big change
3000 3003
3001 if (curtab->tp_first_diff == NULL) // no diffs today 3004 if (curtab->tp_first_diff == NULL) // no diffs today
3002 return lnum1; 3005 return lnum1;
3003 3006
3004 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) 3007 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
3005 { 3008 {
3006 if (dp->df_lnum[idx1] > lnum1) 3009 if (dp->df_lnum[idx1] > lnum1)
3007 return lnum1 - baseline; 3010 return lnum1 - baseline;
3008 if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) 3011 if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1)
3009 { 3012 {
3068 3071
3069 if (curtab->tp_diff_invalid) 3072 if (curtab->tp_diff_invalid)
3070 ex_diffupdate(NULL); // update after a big change 3073 ex_diffupdate(NULL); // update after a big change
3071 3074
3072 // search for a change that includes "lnum" in the list of diffblocks. 3075 // search for a change that includes "lnum" in the list of diffblocks.
3073 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) 3076 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp)
3074 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) 3077 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx])
3075 break; 3078 break;
3076 3079
3077 // When after the last change, compute relative to the last line number. 3080 // When after the last change, compute relative to the last line number.
3078 if (dp == NULL) 3081 if (dp == NULL)