To: vim_dev@googlegroups.com Subject: Patch 9.0.1614 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1614 Problem: strlen() called too often for :spellrepall. Solution: Store the result in a variable. (closes #12497) Files: src/spell.c, src/testdir/test_spell.vim *** ../vim-9.0.1613/src/spell.c 2023-05-25 17:14:18.219481255 +0100 --- src/spell.c 2023-06-06 15:57:43.521597343 +0100 *************** *** 2890,2896 **** { pos_T pos = curwin->w_cursor; char_u *frompat; - int addlen; char_u *line; char_u *p; int save_ws = p_ws; --- 2890,2895 ---- *************** *** 2901,2909 **** emsg(_(e_no_previous_spell_replacement)); return; } ! addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from)); ! frompat = alloc(STRLEN(repl_from) + 7); if (frompat == NULL) return; sprintf((char *)frompat, "\\V\\<%s\\>", repl_from); --- 2900,2910 ---- emsg(_(e_no_previous_spell_replacement)); return; } ! 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,2935 **** // when changing "etc" to "etc.". line = ml_get_curline(); if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, ! repl_to, STRLEN(repl_to)) != 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)); ml_replace(curwin->w_cursor.lnum, p, FALSE); changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); #if defined(FEAT_PROP_POPUP) --- 2923,2936 ---- // when changing "etc" to "etc.". line = ml_get_curline(); if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, ! 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 + 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,2951 **** } ++sub_nsubs; } ! curwin->w_cursor.col += (colnr_T)STRLEN(repl_to); } p_ws = save_ws; --- 2946,2952 ---- } ++sub_nsubs; } ! curwin->w_cursor.col += (colnr_T)repl_to_len; } p_ws = save_ws; *** ../vim-9.0.1613/src/testdir/test_spell.vim 2023-05-31 18:57:10.513953154 +0100 --- src/testdir/test_spell.vim 2023-06-06 15:54:26.798124994 +0100 *************** *** 281,287 **** set spell& spelllang& dictionary& ignorecase& endfunc ! func Test_spellreall() new set spell call assert_fails('spellrepall', 'E752:') --- 281,287 ---- set spell& spelllang& dictionary& ignorecase& endfunc ! func Test_spellrepall() new set spell call assert_fails('spellrepall', 'E752:') *** ../vim-9.0.1613/src/version.c 2023-06-05 21:52:41.847715785 +0100 --- src/version.c 2023-06-06 15:56:26.689802604 +0100 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1614, /**/ -- hundred-and-one symptoms of being an internet addict: 122. You ask if the Netaholics Anonymous t-shirt you ordered can be sent to you via e-mail. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///