Skip to content

Commit

Permalink
perf: fast return for Util.ls when file found
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 28, 2022
1 parent 28af1e1 commit 073b5e3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lua/lazy/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,17 @@ end

---@alias FileType "file"|"directory"|"link"
---@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)
local handle = vim.loop.fs_scandir(path)
while handle do
local name, t = vim.loop.fs_scandir_next(handle)
if not name then
break
end
fn(path .. "/" .. name, name, t)
if fn(path .. "/" .. name, name, t) == false then
break
end
end
end

Expand Down

0 comments on commit 073b5e3

Please sign in to comment.