diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-08-24 15:14:23 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-08-24 22:40:56 +0200 |
commit | cefd774fac76b91f5368833555818c80c992c3b1 (patch) | |
tree | 146d6cb8fde01d28c5b03b9640f9e2515c4a89b7 /src/nvim/diff.c | |
parent | daf7abbc4238dc269e22dd431bc4b1627ef9b6a1 (diff) | |
download | rneovim-cefd774fac76b91f5368833555818c80c992c3b1.tar.gz rneovim-cefd774fac76b91f5368833555818c80c992c3b1.tar.bz2 rneovim-cefd774fac76b91f5368833555818c80c992c3b1.zip |
refactor(memline): distinguish mutating uses of ml_get_buf()
ml_get_buf() takes a third parameters to indicate whether the
caller wants to mutate the memline data in place. However
the vast majority of the call sites is using this function
just to specify a buffer but without any mutation. This makes
it harder to grep for the places which actually perform mutation.
Solution: Remove the bool param from ml_get_buf(). it now works
like ml_get() except for a non-current buffer. Add a new
ml_get_buf_mut() function for the mutating use-case, which can
be grepped along with the other ml_replace() etc functions which
can modify the memline.
Diffstat (limited to 'src/nvim/diff.c')
-rw-r--r-- | src/nvim/diff.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 1f8d21220b..d3bd9f7754 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -596,9 +596,7 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) if (dir == BACKWARD) { off_org = dp->df_count[i_org] - 1; } - char *line_org = xstrdup(ml_get_buf(tp->tp_diffbuf[i_org], - dp->df_lnum[i_org] + off_org, - false)); + char *line_org = xstrdup(ml_get_buf(tp->tp_diffbuf[i_org], dp->df_lnum[i_org] + off_org)); int i_new; for (i_new = i_org + 1; i_new < DB_COUNT; i_new++) { @@ -616,8 +614,7 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) } if (diff_cmp(line_org, ml_get_buf(tp->tp_diffbuf[i_new], - dp->df_lnum[i_new] + off_new, - false)) != 0) { + dp->df_lnum[i_new] + off_new)) != 0) { break; } } @@ -756,7 +753,7 @@ static int diff_write_buffer(buf_T *buf, mmfile_t *m, linenr_T start, linenr_T e // xdiff requires one big block of memory with all the text. for (linenr_T lnum = start; lnum <= end; lnum++) { - len += strlen(ml_get_buf(buf, lnum, false)) + 1; + len += strlen(ml_get_buf(buf, lnum)) + 1; } char *ptr = try_malloc(len); if (ptr == NULL) { @@ -777,7 +774,7 @@ static int diff_write_buffer(buf_T *buf, mmfile_t *m, linenr_T start, linenr_T e len = 0; for (linenr_T lnum = start; lnum <= end; lnum++) { - char *s = ml_get_buf(buf, lnum, false); + char *s = ml_get_buf(buf, lnum); if (diff_flags & DIFF_ICASE) { while (*s != NUL) { char cbuf[MB_MAXBYTES + 1]; @@ -2244,11 +2241,9 @@ static bool diff_equal_entry(diff_T *dp, int idx1, int idx2) } for (int i = 0; i < dp->df_count[idx1]; i++) { - char *line = xstrdup(ml_get_buf(curtab->tp_diffbuf[idx1], - dp->df_lnum[idx1] + i, false)); + char *line = xstrdup(ml_get_buf(curtab->tp_diffbuf[idx1], dp->df_lnum[idx1] + i)); - int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], - dp->df_lnum[idx2] + i, false)); + int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], dp->df_lnum[idx2] + i)); xfree(line); if (cmp != 0) { @@ -2617,7 +2612,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { // Make a copy of the line, the next ml_get() will invalidate it. - char *line_org = xstrdup(ml_get_buf(wp->w_buffer, lnum, false)); + char *line_org = xstrdup(ml_get_buf(wp->w_buffer, lnum)); int idx = diff_buf_idx(wp->w_buffer); if (idx == DB_COUNT) { @@ -2661,7 +2656,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) continue; } added = false; - char *line_new = ml_get_buf(curtab->tp_diffbuf[i], dp->df_lnum[i] + off, false); + char *line_new = ml_get_buf(curtab->tp_diffbuf[i], dp->df_lnum[i] + off); // Search for start of difference si_org = si_new = 0; @@ -3097,7 +3092,7 @@ static void diffgetput(const int addr_count, const int idx_cur, const int idx_fr if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) { break; } - char *p = xstrdup(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, false)); + char *p = xstrdup(ml_get_buf(curtab->tp_diffbuf[idx_from], nr)); ml_append(lnum + i - 1, p, 0, false); xfree(p); added++; |