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.
This commit is contained in:
Lewis Russell authored and Lewis Russell committed 2024-03-06 10:57:04 +00:00
1 parent ea44f74d84
commit 3d2aeec68d
1 file changed
+13 -10
+13 -10
View File
@@ -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
return true
end
local j = 1
for _ in
pairs(t--[[@as table<any,any>]])
do
if t[j] == nil then
return false
end
j = j + 1
end
return true
end
--- Counts the number of non-nil values in table `t`.