diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-06-18 12:37:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-18 12:37:27 +0200 |
commit | 96d83e2a66734b1bbbf863583e90a6fb6e646a67 (patch) | |
tree | ca940592e78b3bc6ee2fb99de53215b4d9c016d4 /src | |
parent | e2d3ad7bc4685c38f037a631ce345a64217c233b (diff) | |
parent | a85e8a186b089999c258b21fb2f7b62b58920884 (diff) | |
download | rneovim-96d83e2a66734b1bbbf863583e90a6fb6e646a67.tar.gz rneovim-96d83e2a66734b1bbbf863583e90a6fb6e646a67.tar.bz2 rneovim-96d83e2a66734b1bbbf863583e90a6fb6e646a67.zip |
Merge pull request #14824 from vigoux/extmarks-ts-perf
perf(extmarks): allow ephemeral extmarks past EOF to remove O(strlen^2) cost of tree-sitter
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/buffer.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index f84e8c99a4..b371c08d2a 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1489,21 +1489,6 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, return 0; } - size_t len = 0; - if (line < 0 || line > buf->b_ml.ml_line_count) { - api_set_error(err, kErrorTypeValidation, "line value outside range"); - return 0; - } else if (line < buf->b_ml.ml_line_count) { - len = STRLEN(ml_get_buf(buf, (linenr_T)line+1, false)); - } - - if (col == -1) { - col = (Integer)len; - } else if (col < -1 || col > (Integer)len) { - api_set_error(err, kErrorTypeValidation, "col value outside range"); - return 0; - } - bool ephemeral = false; uint64_t id = 0; @@ -1674,6 +1659,22 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, } } + size_t len = 0; + if (line < 0 || line > buf->b_ml.ml_line_count) { + api_set_error(err, kErrorTypeValidation, "line value outside range"); + return 0; + } else if (line < buf->b_ml.ml_line_count) { + len = ephemeral ? MAXCOL : STRLEN(ml_get_buf(buf, (linenr_T)line+1, false)); + } + + if (col == -1) { + col = (Integer)len; + } else if (col < -1 || col > (Integer)len) { + api_set_error(err, kErrorTypeValidation, "col value outside range"); + return 0; + } + + // Only error out if they try to set end_right_gravity without // setting end_col or end_line if (line2 == -1 && col2 == -1 && end_gravity_set) { @@ -1684,7 +1685,8 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, if (col2 >= 0) { if (line2 >= 0 && line2 < buf->b_ml.ml_line_count) { - len = STRLEN(ml_get_buf(buf, (linenr_T)line2 + 1, false)); + len = ephemeral ? MAXCOL : STRLEN( + ml_get_buf(buf, (linenr_T)line2 + 1, false)); } else if (line2 == buf->b_ml.ml_line_count) { // We are trying to add an extmark past final newline len = 0; |