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.
This commit is contained in:
bfredl
2023-08-24 15:14:23 +02:00
parent daf7abbc42
commit cefd774fac
43 changed files with 134 additions and 123 deletions

View File

@@ -6423,7 +6423,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl, bool crl
buf_T *buf = buflist_findnr((int)tv->vval.v_number);
if (buf) {
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
for (char *p = ml_get_buf(buf, lnum, false); *p != NUL; p++) {
for (char *p = ml_get_buf(buf, lnum); *p != NUL; p++) {
*len += 1;
}
*len += 1;
@@ -6441,7 +6441,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl, bool crl
char *ret = xmalloc((size_t)(*len) + 1);
char *end = ret;
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
for (char *p = ml_get_buf(buf, lnum, false); *p != NUL; p++) {
for (char *p = ml_get_buf(buf, lnum); *p != NUL; p++) {
*end++ = (*p == '\n') ? NUL : *p;
}
*end++ = '\n';
@@ -6493,7 +6493,7 @@ int buf_byteidx_to_charidx(buf_T *buf, linenr_T lnum, int byteidx)
lnum = buf->b_ml.ml_line_count;
}
char *str = ml_get_buf(buf, lnum, false);
char *str = ml_get_buf(buf, lnum);
if (*str == NUL) {
return 0;
@@ -6531,7 +6531,7 @@ int buf_charidx_to_byteidx(buf_T *buf, linenr_T lnum, int charidx)
lnum = buf->b_ml.ml_line_count;
}
char *str = ml_get_buf(buf, lnum, false);
char *str = ml_get_buf(buf, lnum);
// Convert the character offset to a byte offset
char *t = str;