Mercurial > vim
diff src/textprop.c @ 34540:9e093c96dff6 v9.1.0172
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Commit: https://github.com/vim/vim/commit/94b7c3233ef534acc669b3083ed1fe59cf3a090b
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue Mar 12 21:50:32 2024 +0100
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Problem: More code can use ml_get_buf_len() instead of STRLEN().
Solution: Change more STRLEN() calls to ml_get_buf_len(). Also do not
set ml_line_textlen in ml_replace_len() if "has_props" is set,
because "len_arg" also includes the size of text properties in
that case. (zeertzjq)
closes: #14183
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 12 Mar 2024 22:00:04 +0100 |
parents | f0cdbcf53264 |
children | 83875247fbc0 |
line wrap: on
line diff
--- a/src/textprop.c +++ b/src/textprop.c @@ -637,7 +637,7 @@ get_text_props(buf_T *buf, linenr_T lnum // Fetch the line to get the ml_line_len field updated. text = ml_get_buf(buf, lnum, will_change); - textlen = STRLEN(text) + 1; + textlen = ml_get_buf_len(buf, lnum) + 1; proplen = buf->b_ml.ml_line_len - textlen; if (proplen == 0) return 0; @@ -864,7 +864,7 @@ set_text_props(linenr_T lnum, char_u *pr int textlen; text = ml_get(lnum); - textlen = (int)STRLEN(text) + 1; + textlen = ml_get_len(lnum) + 1; newtext = alloc(textlen + len); if (newtext == NULL) return; @@ -1091,7 +1091,7 @@ f_prop_clear(typval_T *argvars, typval_T if (lnum > buf->b_ml.ml_line_count) break; text = ml_get_buf(buf, lnum, FALSE); - len = STRLEN(text) + 1; + len = ml_get_buf_len(buf, lnum) + 1; if ((size_t)buf->b_ml.ml_line_len > len) { did_clear = TRUE; @@ -1221,7 +1221,7 @@ f_prop_find(typval_T *argvars, typval_T while (1) { char_u *text = ml_get_buf(buf, lnum, FALSE); - size_t textlen = STRLEN(text) + 1; + size_t textlen = ml_get_buf_len(buf, lnum) + 1; int count = (int)((buf->b_ml.ml_line_len - textlen) / sizeof(textprop_T)); int i; @@ -1342,7 +1342,7 @@ get_props_in_line( int add_lnum) { char_u *text = ml_get_buf(buf, lnum, FALSE); - size_t textlen = STRLEN(text) + 1; + size_t textlen = ml_get_buf_len(buf, lnum) + 1; int count; int i; textprop_T prop; @@ -1675,13 +1675,11 @@ f_prop_remove(typval_T *argvars, typval_ end = buf->b_ml.ml_line_count; for (lnum = start; lnum <= end; ++lnum) { - char_u *text; size_t len; if (lnum > buf->b_ml.ml_line_count) break; - text = ml_get_buf(buf, lnum, FALSE); - len = STRLEN(text) + 1; + len = ml_get_buf_len(buf, lnum) + 1; if ((size_t)buf->b_ml.ml_line_len > len) { static textprop_T textprop; // static because of alignment