changeset 32564:238e25832d07 v9.0.1614

patch 9.0.1614: strlen() called too often for :spellrepall Commit: https://github.com/vim/vim/commit/59f7038536a370d771758dc34036cc1424be7421 Author: zeertzjq <zeertzjq@outlook.com> Date: Tue Jun 6 15:59:59 2023 +0100 patch 9.0.1614: strlen() called too often for :spellrepall Problem: strlen() called too often for :spellrepall. Solution: Store the result in a variable. (closes https://github.com/vim/vim/issues/12497)
author Bram Moolenaar <Bram@vim.org>
date Tue, 06 Jun 2023 17:15:05 +0200
parents ea223b114b03
children e140237b3b9b
files src/spell.c src/testdir/test_spell.vim src/version.c
diffstat 3 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/spell.c
+++ b/src/spell.c
@@ -2890,7 +2890,6 @@ ex_spellrepall(exarg_T *eap UNUSED)
 {
     pos_T	pos = curwin->w_cursor;
     char_u	*frompat;
-    int		addlen;
     char_u	*line;
     char_u	*p;
     int		save_ws = p_ws;
@@ -2901,9 +2900,11 @@ ex_spellrepall(exarg_T *eap UNUSED)
 	emsg(_(e_no_previous_spell_replacement));
 	return;
     }
-    addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from));
-
-    frompat = alloc(STRLEN(repl_from) + 7);
+    size_t	repl_from_len = STRLEN(repl_from);
+    size_t	repl_to_len = STRLEN(repl_to);
+    int		addlen = (int)(repl_to_len - repl_from_len);
+
+    frompat = alloc(repl_from_len + 7);
     if (frompat == NULL)
 	return;
     sprintf((char *)frompat, "\\V\\<%s\\>", repl_from);
@@ -2922,14 +2923,14 @@ ex_spellrepall(exarg_T *eap UNUSED)
 	// when changing "etc" to "etc.".
 	line = ml_get_curline();
 	if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col,
-					       repl_to, STRLEN(repl_to)) != 0)
+						   repl_to, repl_to_len) != 0)
 	{
 	    p = alloc(STRLEN(line) + addlen + 1);
 	    if (p == NULL)
 		break;
 	    mch_memmove(p, line, curwin->w_cursor.col);
 	    STRCPY(p + curwin->w_cursor.col, repl_to);
-	    STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from));
+	    STRCAT(p, line + curwin->w_cursor.col + repl_from_len);
 	    ml_replace(curwin->w_cursor.lnum, p, FALSE);
 	    changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
 #if defined(FEAT_PROP_POPUP)
@@ -2945,7 +2946,7 @@ ex_spellrepall(exarg_T *eap UNUSED)
 	    }
 	    ++sub_nsubs;
 	}
-	curwin->w_cursor.col += (colnr_T)STRLEN(repl_to);
+	curwin->w_cursor.col += (colnr_T)repl_to_len;
     }
 
     p_ws = save_ws;
--- a/src/testdir/test_spell.vim
+++ b/src/testdir/test_spell.vim
@@ -281,7 +281,7 @@ func Test_compl_with_CTRL_X_CTRL_K_using
   set spell& spelllang& dictionary& ignorecase&
 endfunc
 
-func Test_spellreall()
+func Test_spellrepall()
   new
   set spell
   call assert_fails('spellrepall', 'E752:')
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1614,
+/**/
     1613,
 /**/
     1612,