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)

c6c1ec4da5

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2023-02-24 15:31:43 +08:00
parent d9263688bf
commit ec25572367
2 changed files with 2 additions and 4 deletions

View File

@ -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;

View File

@ -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++;