neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 3d2aeec68d6a03a07394eea154447166f6487078
parent ea44f74d84f87ce5aff2ef7797be986900bd74a6
Author: Lewis Russell <lewis6991@gmail.com>
Date:   Wed,  6 Mar 2024 09:40:11 +0000

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:
Mruntime/lua/vim/shared.lua | 21++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)

diff --git 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`.