]> granicus.if.org Git - vim/commitdiff
patch 8.2.2736: Vim9: for loop over string is a bit slow v8.2.2736
authorBram Moolenaar <Bram@vim.org>
Thu, 8 Apr 2021 16:05:03 +0000 (18:05 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 8 Apr 2021 16:05:03 +0000 (18:05 +0200)
Problem:    Vim9: for loop over string is a bit slow.
Solution:   Avoid using strlen().

src/version.c
src/vim9execute.c

index f1534f128491036bff855cf9c0156c205d5215d5..4e6435c31db007b0235baf5148ddf7cbd5756101 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2736,
 /**/
     2735,
 /**/
index d3e2af772a0b9b2dee12bf64e8b724d2cea55719..d6c47648824267ae2f6421a4fb78fb0f671d782b 100644 (file)
@@ -2792,12 +2792,11 @@ call_def_function(
                    else if (ltv->v_type == VAR_STRING)
                    {
                        char_u  *str = ltv->vval.v_string;
-                       int     len = str == NULL ? 0 : (int)STRLEN(str);
 
                        // Push the next character from the string.  The index
                        // is for the last byte of the previous character.
                        ++idxtv->vval.v_number;
-                       if (idxtv->vval.v_number >= len)
+                       if (str == NULL || str[idxtv->vval.v_number] == NUL)
                        {
                            // past the end of the string, jump to "endfor"
                            ectx.ec_iidx = iptr->isn_arg.forloop.for_end;