1
0
forked from aniani/vim

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. (#5541)
This commit is contained in:
Bram Moolenaar
2020-01-30 16:40:10 +01:00
parent 21109272f5
commit 9f2d020d39
2 changed files with 24 additions and 12 deletions

View 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)
{
n = tv_get_number_chk(&li->li_tv, &error);
for (;;)
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
{
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;
}
}
}
}

View File

@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
182,
/**/
181,
/**/