diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-01-02 12:33:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-02 12:33:41 -0800 |
commit | 3f35c69b23d1bc951f158e4e3d8e554f89bd1037 (patch) | |
tree | dc4f272a6a7968089d17fd741c37628d6d59fd35 /src/nvim/api/buffer.c | |
parent | 91d76ac941a26f8370c48e062b5e09f98c75f7bc (diff) | |
download | rneovim-3f35c69b23d1bc951f158e4e3d8e554f89bd1037.tar.gz rneovim-3f35c69b23d1bc951f158e4e3d8e554f89bd1037.tar.bz2 rneovim-3f35c69b23d1bc951f158e4e3d8e554f89bd1037.zip |
refactor(api): redundant `ml_mfp` check #26059
buf_ensure_loaded already checks `(buf->b_ml.ml_mfp != NULL)`. #25823
TODO:
- #10070 #13201 All buffer-related API functions except
`nvim_buf_is_loaded` (and `nvim_buf_is_valid`?) should always call
`buf_ensure_loaded`. Because the _common case_ is that plugins expect
the buffer to "just work"—and for the uncomon, performance-sensitive
case, the script can check `nvim_buf_is_loaded` to avoid implicitly
loading a buffer.
- Update documentation to clarify the above semantics.
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r-- | src/nvim/api/buffer.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 3cb1512bb6..c07e760469 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -335,12 +335,10 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ return; } - // load buffer first if it's not loaded - if (buf->b_ml.ml_mfp == NULL) { - if (!buf_ensure_loaded(buf)) { - api_set_error(err, kErrorTypeException, "Failed to load buffer"); - return; - } + // Load buffer if necessary. #22670 + if (!buf_ensure_loaded(buf)) { + api_set_error(err, kErrorTypeException, "Failed to load buffer"); + return; } bool oob = false; @@ -517,12 +515,10 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In return; } - // load buffer first if it's not loaded - if (buf->b_ml.ml_mfp == NULL) { - if (!buf_ensure_loaded(buf)) { - api_set_error(err, kErrorTypeException, "Failed to load buffer"); - return; - } + // Load buffer if necessary. #22670 + if (!buf_ensure_loaded(buf)) { + api_set_error(err, kErrorTypeException, "Failed to load buffer"); + return; } bool oob = false; |