perf: fast return for Util.ls when file found

This commit is contained in:
Folke Lemaitre 2022-11-28 11:35:47 +01:00
parent 28af1e1ac3
commit 073b5e3caa
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 4 additions and 2 deletions

View File

@ -108,7 +108,7 @@ end
---@alias FileType "file"|"directory"|"link" ---@alias FileType "file"|"directory"|"link"
---@param path string ---@param path string
---@param fn fun(path: string, name:string, type:FileType) ---@param fn fun(path: string, name:string, type:FileType):boolean?
function M.ls(path, fn) function M.ls(path, fn)
local handle = vim.loop.fs_scandir(path) local handle = vim.loop.fs_scandir(path)
while handle do while handle do
@ -116,7 +116,9 @@ function M.ls(path, fn)
if not name then if not name then
break break
end end
fn(path .. "/" .. name, name, t) if fn(path .. "/" .. name, name, t) == false then
break
end
end end
end end