# HG changeset patch # User Bram Moolenaar # Date 1580399104 -3600 # Node ID c077438ceb93595c3822d683e300e1bcde9257c6 # Parent fb4df26177a5523e752c9975cefbb1a2c879f15a patch 8.2.0182: min() and max() materialize a range() list Commit: https://github.com/vim/vim/commit/9f2d020d396132ecbc0be6faa1de29c7078bb5ac Author: Bram Moolenaar Date: Thu Jan 30 16:40:10 2020 +0100 patch 8.2.0182: min() and max() materialize a range() list Problem: Min() and max() materialize a range() list. Solution: Compute the result without materializing the list. (https://github.com/vim/vim/issues/5541) diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -4881,21 +4881,31 @@ max_min(typval_T *argvars, typval_T *ret 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; + } } } } diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 182, +/**/ 181, /**/ 180,