diff options
author | Cédric Barreteau <> | 2020-06-30 18:39:54 +0200 |
---|---|---|
committer | Cédric Barreteau <> | 2020-07-15 20:27:20 +0200 |
commit | 6420615e3f703870ed898083f84d6e3515a8c279 (patch) | |
tree | 4ccc6606a2fc3b900f1c6a40e28a778e73762695 /src/nvim/eval/funcs.c | |
parent | a02a267f8ad4b6d8b9038d2c7d9b85f03e734814 (diff) | |
download | rneovim-6420615e3f703870ed898083f84d6e3515a8c279.tar.gz rneovim-6420615e3f703870ed898083f84d6e3515a8c279.tar.bz2 rneovim-6420615e3f703870ed898083f84d6e3515a8c279.zip |
vim-patch:8.2.0935: flattening a list with existing code is slow
Problem: Flattening a list with existing code is slow.
Solution: Add flatten(). (Mopp, closes vim/vim#3676)
https://github.com/vim/vim/commit/077a1e670ad69ef4cefc22103ca6635bd269e764
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r-- | src/nvim/eval/funcs.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 99014d1a09..95686b97bf 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2160,6 +2160,42 @@ static void f_expandcmd(typval_T *argvars, typval_T *rettv, FunPtr fptr) rettv->vval.v_string = cmdstr; } + +/// "flatten(list[, {maxdepth}])" function +static void f_flatten(typval_T *argvars, typval_T *rettv, FunPtr fptr) +{ + list_T *list; + long maxdepth; + bool error = false; + + if (argvars[0].v_type != VAR_LIST) { + EMSG2(_(e_listarg), "flatten()"); + return; + } + + if (argvars[1].v_type == VAR_UNKNOWN) { + maxdepth = 999999; + } else { + maxdepth = (long)tv_get_number_chk(&argvars[1], &error); + if (error) { + return; + } + if (maxdepth < 0) { + EMSG(_("E900: maxdepth must be non-negative number")); + return; + } + } + + list = argvars[0].vval.v_list; + if (list != NULL + && !tv_check_lock(tv_list_locked(list), + N_("flatten() argument"), + TV_TRANSLATE) + && tv_list_flatten(list, maxdepth) == OK) { + tv_copy(&argvars[0], rettv); + } +} + /* * "extend(list, list [, idx])" function * "extend(dict, dict [, action])" function |