Skip to content

Commit 1da13ad

Browse files
authored
feat: defer libuv calls in Path:new (#369)
1 parent 5dc860a commit 1da13ad

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lua/plenary/path.lua

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,24 @@ local check_self = function(self)
165165
return self
166166
end
167167

168-
Path.__index = Path
168+
Path.__index = function(t, k)
169+
local raw = rawget(Path, k)
170+
if raw then
171+
return raw
172+
end
173+
174+
if k == "_cwd" then
175+
local cwd = uv.fs_realpath "."
176+
t._cwd = cwd
177+
return cwd
178+
end
179+
180+
if k == "_absolute" then
181+
local absolute = uv.fs_realpath(t.filename)
182+
t._absolute = absolute
183+
return absolute
184+
end
185+
end
169186

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

244261
_sep = sep,
245-
246-
-- Cached values
247-
_absolute = uv.fs_realpath(path_string),
248-
_cwd = uv.fs_realpath ".",
249262
}
250263

251264
setmetatable(obj, Path)

0 commit comments

Comments
 (0)