mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
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:
@ -546,7 +546,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
|
||||
char *str_at_end = NULL;
|
||||
|
||||
// Another call to ml_get_buf() may free the line, so make a copy.
|
||||
str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row, false));
|
||||
str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row));
|
||||
size_t len_at_start = strlen(str_at_start);
|
||||
start_col = start_col < 0 ? (int64_t)len_at_start + start_col + 1 : start_col;
|
||||
VALIDATE_RANGE((start_col >= 0 && (size_t)start_col <= len_at_start), "start_col", {
|
||||
@ -554,7 +554,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
|
||||
});
|
||||
|
||||
// Another call to ml_get_buf() may free the line, so make a copy.
|
||||
str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)end_row, false));
|
||||
str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)end_row));
|
||||
size_t len_at_end = strlen(str_at_end);
|
||||
end_col = end_col < 0 ? (int64_t)len_at_end + end_col + 1 : end_col;
|
||||
VALIDATE_RANGE((end_col >= 0 && (size_t)end_col <= len_at_end), "end_col", {
|
||||
@ -584,7 +584,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
|
||||
for (int64_t i = 1; i < end_row - start_row; i++) {
|
||||
int64_t lnum = start_row + i;
|
||||
|
||||
const char *bufline = ml_get_buf(buf, (linenr_T)lnum, false);
|
||||
const char *bufline = ml_get_buf(buf, (linenr_T)lnum);
|
||||
old_byte += (bcount_t)(strlen(bufline)) + 1;
|
||||
}
|
||||
old_byte += (bcount_t)end_col + 1;
|
||||
@ -1415,7 +1415,7 @@ bool buf_collect_lines(buf_T *buf, size_t n, linenr_T start, int start_idx, bool
|
||||
return false;
|
||||
}
|
||||
|
||||
char *bufstr = ml_get_buf(buf, lnum, false);
|
||||
char *bufstr = ml_get_buf(buf, lnum);
|
||||
push_linestr(lstate, l, bufstr, strlen(bufstr), start_idx + (int)i, replace_nl);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user