Mercurial > vim
comparison src/eval.c @ 6332:65e72747feca v7.4.499
updated for version 7.4.499
Problem: substitute() can be slow with long strings.
Solution: Store a pointer to the end, instead of calling strlen() every
time. (Ozaki Kiichi)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 05 Nov 2014 16:03:44 +0100 |
parents | 5f54e1995751 |
children | 094a87e76155 |
comparison
equal
deleted
inserted
replaced
6331:6a66cccd0e87 | 6332:65e72747feca |
---|---|
25074 int sublen; | 25074 int sublen; |
25075 regmatch_T regmatch; | 25075 regmatch_T regmatch; |
25076 int i; | 25076 int i; |
25077 int do_all; | 25077 int do_all; |
25078 char_u *tail; | 25078 char_u *tail; |
25079 char_u *end; | |
25079 garray_T ga; | 25080 garray_T ga; |
25080 char_u *ret; | 25081 char_u *ret; |
25081 char_u *save_cpo; | 25082 char_u *save_cpo; |
25082 char_u *zero_width = NULL; | 25083 char_u *zero_width = NULL; |
25083 | 25084 |
25092 regmatch.rm_ic = p_ic; | 25093 regmatch.rm_ic = p_ic; |
25093 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); | 25094 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); |
25094 if (regmatch.regprog != NULL) | 25095 if (regmatch.regprog != NULL) |
25095 { | 25096 { |
25096 tail = str; | 25097 tail = str; |
25098 end = str + STRLEN(str); | |
25097 while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) | 25099 while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) |
25098 { | 25100 { |
25099 /* Skip empty match except for first match. */ | 25101 /* Skip empty match except for first match. */ |
25100 if (regmatch.startp[0] == regmatch.endp[0]) | 25102 if (regmatch.startp[0] == regmatch.endp[0]) |
25101 { | 25103 { |
25118 * - The text up to where the match is. | 25120 * - The text up to where the match is. |
25119 * - The substituted text. | 25121 * - The substituted text. |
25120 * - The text after the match. | 25122 * - The text after the match. |
25121 */ | 25123 */ |
25122 sublen = vim_regsub(®match, sub, tail, FALSE, TRUE, FALSE); | 25124 sublen = vim_regsub(®match, sub, tail, FALSE, TRUE, FALSE); |
25123 if (ga_grow(&ga, (int)(STRLEN(tail) + sublen - | 25125 if (ga_grow(&ga, (int)((end - tail) + sublen - |
25124 (regmatch.endp[0] - regmatch.startp[0]))) == FAIL) | 25126 (regmatch.endp[0] - regmatch.startp[0]))) == FAIL) |
25125 { | 25127 { |
25126 ga_clear(&ga); | 25128 ga_clear(&ga); |
25127 break; | 25129 break; |
25128 } | 25130 } |