From ec2557236710f3e062164e7ff4b137b2a0d8dfa4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 24 Feb 2023 15:31:43 +0800 Subject: [PATCH] vim-patch:8.2.4629: flattennew() makes a deep copy unnecessarily Problem: flattennew() makes a deep copy unnecessarily. Solution: Use a shallow copy. (issue vim/vim#10012) https://github.com/vim/vim/commit/c6c1ec4da53db9d292fa3dd081c20123f8261178 Co-authored-by: Bram Moolenaar --- src/nvim/eval/funcs.c | 2 +- src/nvim/eval/typval.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 6ac94706c7..f1852f1b6d 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -1902,7 +1902,7 @@ static void flatten_common(typval_T *argvars, typval_T *rettv, bool make_copy) } if (make_copy) { - list = tv_list_copy(NULL, list, true, get_copyID()); + list = tv_list_copy(NULL, list, false, get_copyID()); rettv->vval.v_list = list; if (list == NULL) { return; diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 125a4310d8..9faf19c364 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -659,7 +659,6 @@ void tv_list_flatten(list_T *list, listitem_T *first, long maxitems, long maxdep FUNC_ATTR_NONNULL_ARG(1) { listitem_T *item; - listitem_T *to_free; int done = 0; if (maxdepth == 0) { return; @@ -684,14 +683,13 @@ void tv_list_flatten(list_T *list, listitem_T *first, long maxitems, long maxdep tv_list_drop_items(list, item, item); tv_list_extend(list, itemlist, next); tv_clear(&item->li_tv); - to_free = item; if (maxdepth > 0) { tv_list_flatten(list, item->li_prev == NULL ? list->lv_first : item->li_prev->li_next, itemlist->lv_len, maxdepth - 1); } - xfree(to_free); + xfree(item); } done++;