aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-08-24 15:14:23 +0200
committerbfredl <bjorn.linse@gmail.com>2023-08-24 22:40:56 +0200
commitcefd774fac76b91f5368833555818c80c992c3b1 (patch)
tree146d6cb8fde01d28c5b03b9640f9e2515c4a89b7 /src/nvim/ops.c
parentdaf7abbc4238dc269e22dd431bc4b1627ef9b6a1 (diff)
downloadrneovim-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/ops.c')
-rw-r--r--src/nvim/ops.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 0aefd28fec..0564e3dde2 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -1373,7 +1373,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg)
return false;
}
- *argp = ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false);
+ *argp = ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum);
return true;
case '_': // black hole: always empty
@@ -1783,7 +1783,7 @@ static void mb_adjust_opend(oparg_T *oap)
static inline void pbyte(pos_T lp, int c)
{
assert(c <= UCHAR_MAX);
- *(ml_get_buf(curbuf, lp.lnum, true) + lp.col) = (char)c;
+ *(ml_get_buf_mut(curbuf, lp.lnum) + lp.col) = (char)c;
if (!curbuf_splice_pending) {
extmark_splice_cols(curbuf, (int)lp.lnum - 1, lp.col, 1, 1, kExtmarkUndo);
}
@@ -6915,14 +6915,14 @@ bcount_t get_region_bytecount(buf_T *buf, linenr_T start_lnum, linenr_T end_lnum
if (start_lnum == end_lnum) {
return end_col - start_col;
}
- const char *first = ml_get_buf(buf, start_lnum, false);
+ const char *first = ml_get_buf(buf, start_lnum);
bcount_t deleted_bytes = (bcount_t)strlen(first) - start_col + 1;
for (linenr_T i = 1; i <= end_lnum - start_lnum - 1; i++) {
if (start_lnum + i > max_lnum) {
return deleted_bytes;
}
- deleted_bytes += (bcount_t)strlen(ml_get_buf(buf, start_lnum + i, false)) + 1;
+ deleted_bytes += (bcount_t)strlen(ml_get_buf(buf, start_lnum + i)) + 1;
}
if (end_lnum > max_lnum) {
return deleted_bytes;