]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.0182: min() and max() materialize a range() list v8.2.0182
authorBram Moolenaar <Bram@vim.org>
Thu, 30 Jan 2020 15:40:10 +0000 (16:40 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 30 Jan 2020 15:40:10 +0000 (16:40 +0100)
Problem:    Min() and max() materialize a range() list.
Solution:   Compute the result without materializing the list. (#5541)

src/evalfunc.c
src/version.c

index 19f7294390f2fab05697ef241125f27a5e632b6a..15b799088d970f60c0b90b00aefce20630e1b76e 100644 (file)
@@ -4881,21 +4881,31 @@ max_min(typval_T *argvars, typval_T *rettv, int domax)
        listitem_T      *li;
 
        l = argvars[0].vval.v_list;
-       if (l != NULL)
+       if (l != NULL && l->lv_len > 0)
        {
-           range_list_materialize(l);
-           li = l->lv_first;
-           if (li != NULL)
+           if (l->lv_first == &range_list_item)
+           {
+               if ((l->lv_u.nonmat.lv_stride > 0) ^ domax)
+                   n = l->lv_u.nonmat.lv_start;
+               else
+                   n = l->lv_u.nonmat.lv_start + (l->lv_len - 1)
+                                                   * l->lv_u.nonmat.lv_stride;
+           }
+           else
            {
-               n = tv_get_number_chk(&li->li_tv, &error);
-               for (;;)
+               li = l->lv_first;
+               if (li != NULL)
                {
-                   li = li->li_next;
-                   if (li == NULL)
-                       break;
-                   i = tv_get_number_chk(&li->li_tv, &error);
-                   if (domax ? i > n : i < n)
-                       n = i;
+                   n = tv_get_number_chk(&li->li_tv, &error);
+                   for (;;)
+                   {
+                       li = li->li_next;
+                       if (li == NULL)
+                           break;
+                       i = tv_get_number_chk(&li->li_tv, &error);
+                       if (domax ? i > n : i < n)
+                           n = i;
+                   }
                }
            }
        }
index acbc4f2955fa914b926671b700b025bf1a46ba4f..be4da51fc494783b57ce7ae7c1678247e2c21aae 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    182,
 /**/
     181,
 /**/