diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-12 21:50:32 +0100 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2024-03-12 21:50:32 +0100 |
commit | 94b7c3233ef534acc669b3083ed1fe59cf3a090b (patch) | |
tree | b7d882e3b2cf90034e730023c01214b7b17294af /src/ex_cmds.c | |
parent | 5cac1a9bee0798d70a7fd80363a1f697759638e8 (diff) |
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()v9.1.0172
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>
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r-- | src/ex_cmds.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c index a12d819b3f..d0fc928e65 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -489,7 +489,7 @@ ex_sort(exarg_T *eap) for (lnum = eap->line1; lnum <= eap->line2; ++lnum) { s = ml_get(lnum); - len = (int)STRLEN(s); + len = ml_get_len(lnum); if (maxlen < len) maxlen = len; @@ -691,7 +691,7 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest) return FAIL; for (extra = 0, l = line1; l <= line2; l++) { - str = vim_strsave(ml_get(l + extra)); + str = vim_strnsave(ml_get(l + extra), ml_get_len(l + extra)); if (str != NULL) { ml_append(dest + l - line1, str, (colnr_T)0, FALSE); @@ -824,9 +824,9 @@ ex_copy(linenr_T line1, linenr_T line2, linenr_T n) curwin->w_cursor.lnum = n; while (line1 <= line2) { - // need to use vim_strsave() because the line will be unlocked within + // need to make a copy because the line will be unlocked within // ml_append() - p = vim_strsave(ml_get(line1)); + p = vim_strnsave(ml_get(line1), ml_get_len(line1)); if (p != NULL) { ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); @@ -4225,7 +4225,8 @@ ex_substitute(exarg_T *eap) if (sub_firstline == NULL) { - sub_firstline = vim_strsave(ml_get(sub_firstlnum)); + sub_firstline = vim_strnsave(ml_get(sub_firstlnum), + ml_get_len(sub_firstlnum)); if (sub_firstline == NULL) { vim_free(new_start); @@ -4379,7 +4380,8 @@ ex_substitute(exarg_T *eap) // really update the line, it would change // what matches. Temporarily replace the line // and change it back afterwards. - orig_line = vim_strsave(ml_get(lnum)); + orig_line = vim_strnsave(ml_get(lnum), + ml_get_len(lnum)); if (orig_line != NULL) { char_u *new_line = concat_str(new_start, @@ -4725,7 +4727,8 @@ ex_substitute(exarg_T *eap) { sub_firstlnum += nmatch - 1; vim_free(sub_firstline); - sub_firstline = vim_strsave(ml_get(sub_firstlnum)); + sub_firstline = vim_strnsave(ml_get(sub_firstlnum), + ml_get_len(sub_firstlnum)); // When going beyond the last line, stop substituting. if (sub_firstlnum <= line2) do_again = TRUE; |