aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorFlorian Walch <florian@fwalch.com>2014-12-23 14:35:59 +0100
committerFlorian Walch <florian@fwalch.com>2014-12-23 21:15:31 +0100
commit2ba50a7846290ef399033a8ca34cbf60ef7a6b4e (patch)
treee4ab931cfb5eabdbe4e01a0184bfbd433ba61f41 /src/nvim/eval.c
parent4f6bb8a9a997aacbe9f9f1ca83e7e4c502bdc03c (diff)
downloadrneovim-2ba50a7846290ef399033a8ca34cbf60ef7a6b4e.tar.gz
rneovim-2ba50a7846290ef399033a8ca34cbf60ef7a6b4e.tar.bz2
rneovim-2ba50a7846290ef399033a8ca34cbf60ef7a6b4e.zip
vim-patch: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) https://code.google.com/p/vim/source/detail?r=v7-4-499
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index f50a215559..feb600104f 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -19665,6 +19665,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
regmatch_T regmatch;
int do_all;
char_u *tail;
+ char_u *end;
garray_T ga;
char_u *save_cpo;
char_u *zero_width = NULL;
@@ -19681,6 +19682,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
if (regmatch.regprog != NULL) {
tail = str;
+ end = str + STRLEN(str);
while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str))) {
/* Skip empty match except for first match. */
if (regmatch.startp[0] == regmatch.endp[0]) {
@@ -19703,7 +19705,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
* - The text after the match.
*/
sublen = vim_regsub(&regmatch, sub, tail, FALSE, TRUE, FALSE);
- ga_grow(&ga, (int)(STRLEN(tail) + sublen -
+ ga_grow(&ga, (int)((end - tail) + sublen -
(regmatch.endp[0] - regmatch.startp[0])));
/* copy the text up to where the match is */