diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-03-06 09:40:11 +0000 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-03-06 10:57:04 +0000 |
commit | 3d2aeec68d6a03a07394eea154447166f6487078 (patch) | |
tree | 7e9b242905583d5d0d80807bd6320b1ea1191cd8 /runtime/lua/vim/shared.lua | |
parent | ea44f74d84f87ce5aff2ef7797be986900bd74a6 (diff) | |
download | rneovim-3d2aeec68d6a03a07394eea154447166f6487078.tar.gz rneovim-3d2aeec68d6a03a07394eea154447166f6487078.tar.bz2 rneovim-3d2aeec68d6a03a07394eea154447166f6487078.zip |
refactor(lua): more efficient vim.tbl_islist
No need to run a full iteration of the table. Simply return false when
the next key isn't what we expect.
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r-- | runtime/lua/vim/shared.lua | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index 6e50b87dd5..561d9e3f1b 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -652,18 +652,21 @@ function vim.tbl_islist(t) return false end - local num_elem = vim.tbl_count(t) - - if num_elem == 0 then + if next(t) == nil then return getmetatable(t) ~= vim._empty_dict_mt - else - for i = 1, num_elem do - if t[i] == nil then - return false - end + end + + local j = 1 + for _ in + pairs(t--[[@as table<any,any>]]) + do + if t[j] == nil then + return false end - return true + j = j + 1 end + + return true end --- Counts the number of non-nil values in table `t`. |