Merge pull request #12575 from cbarrete/vim-8.2.0935

[RFC] vim-patch:8.2.{0935,0937}
This commit is contained in:
Matthieu Coudron
2020-07-20 22:04:30 +02:00
committed by GitHub
6 changed files with 190 additions and 0 deletions

View File

@@ -640,6 +640,57 @@ tv_list_copy_error:
return NULL;
}
/// Flatten "list" in place to depth "maxdepth".
/// Does nothing if "maxdepth" is 0.
///
/// @param[in,out] list List to flatten
/// @param[in] maxdepth Maximum depth that will be flattened
///
/// @return OK or FAIL
int tv_list_flatten(list_T *list, long maxdepth)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
{
listitem_T *item;
listitem_T *to_free;
int n;
if (maxdepth == 0) {
return OK;
}
n = 0;
item = list->lv_first;
while (item != NULL) {
fast_breakcheck();
if (got_int) {
return FAIL;
}
if (item->li_tv.v_type == VAR_LIST) {
listitem_T *next = item->li_next;
tv_list_drop_items(list, item, item);
tv_list_extend(list, item->li_tv.vval.v_list, next);
tv_clear(&item->li_tv);
to_free = item;
if (item->li_prev == NULL) {
item = list->lv_first;
} else {
item = item->li_prev->li_next;
}
xfree(to_free);
if (++n >= maxdepth) {
n = 0;
item = next;
}
} else {
n = 0;
item = item->li_next;
}
}
return OK;
}
/// Extend first list with the second
///
/// @param[out] l1 List to extend.