From 82418263fa91792e851cb0de879d1595327d5531 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 28 Sep 2022 16:16:15 +0100 Subject: patch 9.0.0618: calling function for reduce() has too much overhead Problem: Calling function for reduce() has too much overhead. Solution: Do not create a funccall_T every time. --- src/dict.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/dict.c') diff --git a/src/dict.c b/src/dict.c index 1cb3e89a8d..63b30e06be 100644 --- a/src/dict.c +++ b/src/dict.c @@ -1315,6 +1315,8 @@ dict_filter_map( dictitem_T *di; int todo; int rem; + typval_T newtv; + funccall_T *fc; if (filtermap == FILTERMAP_MAPNEW) { @@ -1335,6 +1337,9 @@ dict_filter_map( d_ret = rettv->vval.v_dict; } + // Create one funccal_T for all eval_expr_typval() calls. + fc = eval_expr_get_funccal(expr, &newtv); + if (filtermap != FILTERMAP_FILTER && d->dv_lock == 0) d->dv_lock = VAR_LOCKED; ht = &d->dv_hashtab; @@ -1345,7 +1350,6 @@ dict_filter_map( if (!HASHITEM_EMPTY(hi)) { int r; - typval_T newtv; --todo; di = HI2DI(hi); @@ -1357,8 +1361,7 @@ dict_filter_map( break; set_vim_var_string(VV_KEY, di->di_key, -1); newtv.v_type = VAR_UNKNOWN; - r = filter_map_one(&di->di_tv, expr, filtermap, - &newtv, &rem); + r = filter_map_one(&di->di_tv, expr, filtermap, fc, &newtv, &rem); clear_tv(get_vim_var_tv(VV_KEY)); if (r == FAIL || did_emsg) { @@ -1398,6 +1401,8 @@ dict_filter_map( } hash_unlock(ht); d->dv_lock = prev_lock; + if (fc != NULL) + remove_funccal(); } /* -- cgit v1.2.3