Mercurial > vim
comparison src/spell.c @ 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 | 0632606a2530 |
children | 448aef880252 |
comparison
equal
deleted
inserted
replaced
32563:ea223b114b03 | 32564:238e25832d07 |
---|---|
2888 void | 2888 void |
2889 ex_spellrepall(exarg_T *eap UNUSED) | 2889 ex_spellrepall(exarg_T *eap UNUSED) |
2890 { | 2890 { |
2891 pos_T pos = curwin->w_cursor; | 2891 pos_T pos = curwin->w_cursor; |
2892 char_u *frompat; | 2892 char_u *frompat; |
2893 int addlen; | |
2894 char_u *line; | 2893 char_u *line; |
2895 char_u *p; | 2894 char_u *p; |
2896 int save_ws = p_ws; | 2895 int save_ws = p_ws; |
2897 linenr_T prev_lnum = 0; | 2896 linenr_T prev_lnum = 0; |
2898 | 2897 |
2899 if (repl_from == NULL || repl_to == NULL) | 2898 if (repl_from == NULL || repl_to == NULL) |
2900 { | 2899 { |
2901 emsg(_(e_no_previous_spell_replacement)); | 2900 emsg(_(e_no_previous_spell_replacement)); |
2902 return; | 2901 return; |
2903 } | 2902 } |
2904 addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from)); | 2903 size_t repl_from_len = STRLEN(repl_from); |
2905 | 2904 size_t repl_to_len = STRLEN(repl_to); |
2906 frompat = alloc(STRLEN(repl_from) + 7); | 2905 int addlen = (int)(repl_to_len - repl_from_len); |
2906 | |
2907 frompat = alloc(repl_from_len + 7); | |
2907 if (frompat == NULL) | 2908 if (frompat == NULL) |
2908 return; | 2909 return; |
2909 sprintf((char *)frompat, "\\V\\<%s\\>", repl_from); | 2910 sprintf((char *)frompat, "\\V\\<%s\\>", repl_from); |
2910 p_ws = FALSE; | 2911 p_ws = FALSE; |
2911 | 2912 |
2920 | 2921 |
2921 // Only replace when the right word isn't there yet. This happens | 2922 // Only replace when the right word isn't there yet. This happens |
2922 // when changing "etc" to "etc.". | 2923 // when changing "etc" to "etc.". |
2923 line = ml_get_curline(); | 2924 line = ml_get_curline(); |
2924 if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, | 2925 if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, |
2925 repl_to, STRLEN(repl_to)) != 0) | 2926 repl_to, repl_to_len) != 0) |
2926 { | 2927 { |
2927 p = alloc(STRLEN(line) + addlen + 1); | 2928 p = alloc(STRLEN(line) + addlen + 1); |
2928 if (p == NULL) | 2929 if (p == NULL) |
2929 break; | 2930 break; |
2930 mch_memmove(p, line, curwin->w_cursor.col); | 2931 mch_memmove(p, line, curwin->w_cursor.col); |
2931 STRCPY(p + curwin->w_cursor.col, repl_to); | 2932 STRCPY(p + curwin->w_cursor.col, repl_to); |
2932 STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from)); | 2933 STRCAT(p, line + curwin->w_cursor.col + repl_from_len); |
2933 ml_replace(curwin->w_cursor.lnum, p, FALSE); | 2934 ml_replace(curwin->w_cursor.lnum, p, FALSE); |
2934 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); | 2935 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); |
2935 #if defined(FEAT_PROP_POPUP) | 2936 #if defined(FEAT_PROP_POPUP) |
2936 if (curbuf->b_has_textprop && addlen != 0) | 2937 if (curbuf->b_has_textprop && addlen != 0) |
2937 adjust_prop_columns(curwin->w_cursor.lnum, | 2938 adjust_prop_columns(curwin->w_cursor.lnum, |
2943 ++sub_nlines; | 2944 ++sub_nlines; |
2944 prev_lnum = curwin->w_cursor.lnum; | 2945 prev_lnum = curwin->w_cursor.lnum; |
2945 } | 2946 } |
2946 ++sub_nsubs; | 2947 ++sub_nsubs; |
2947 } | 2948 } |
2948 curwin->w_cursor.col += (colnr_T)STRLEN(repl_to); | 2949 curwin->w_cursor.col += (colnr_T)repl_to_len; |
2949 } | 2950 } |
2950 | 2951 |
2951 p_ws = save_ws; | 2952 p_ws = save_ws; |
2952 curwin->w_cursor = pos; | 2953 curwin->w_cursor = pos; |
2953 vim_free(frompat); | 2954 vim_free(frompat); |