Skip to content

Commit

Permalink
feat: defer libuv calls in Path:new (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdschmidt93 authored May 21, 2022
1 parent 5dc860a commit 1da13ad
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lua/plenary/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,24 @@ local check_self = function(self)
return self
end

Path.__index = Path
Path.__index = function(t, k)
local raw = rawget(Path, k)
if raw then
return raw
end

if k == "_cwd" then
local cwd = uv.fs_realpath "."
t._cwd = cwd
return cwd
end

if k == "_absolute" then
local absolute = uv.fs_realpath(t.filename)
t._absolute = absolute
return absolute
end
end

-- TODO: Could use this to not have to call new... not sure
-- Path.__call = Path:new
Expand Down Expand Up @@ -242,10 +259,6 @@ function Path:new(...)
filename = path_string,

_sep = sep,

-- Cached values
_absolute = uv.fs_realpath(path_string),
_cwd = uv.fs_realpath ".",
}

setmetatable(obj, Path)
Expand Down

0 comments on commit 1da13ad

Please sign in to comment.