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>
diff --git a/src/textprop.c b/src/textprop.c
index cd07844..a976570 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -637,7 +637,7 @@
// 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 @@
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 @@
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 @@
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 @@
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 @@
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