From 5fd330bdc5554581391174448f9a4d5793783f4f Mon Sep 17 00:00:00 2001 From: Ivar Fatland Date: Mon, 15 Jun 2026 09:40:46 +0200 Subject: [PATCH] slight optimization reuse the same folder array. just keep it in memory forever --- nvim/.config/nvim/init.lua | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index 065e8fb..f11d160 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -358,23 +358,27 @@ do return vim.fn.globpath(dir, glob_pattern, false, false, false) ~= '' end - ---return iterator starting from cwd and going upwards until the project - ---root is found by looking for the .git folder. - ---@return fun(): string? - local function all_folders_till_root() + local all_folders_till_root = nil + do local cwd = vim.fn.getcwd() - local folders = {cwd} + local folders = {cwd} -- array of all folders from cwd to root for dir in vim.fs.parents(cwd) do table.insert(folders, dir) end - local curr = 0 - return function() - curr = curr + 1 - local f = folders[curr] - if file_exists(f, '.git') then - curr = -1 + + ---return iterator starting from cwd and going upwards until the project + ---root is found by looking for the .git folder. + ---@return fun(): string? + all_folders_till_root = function() + local curr = 0 + return function() + curr = curr + 1 + local f = folders[curr] + if file_exists(f, '.git') then + curr = -1 + end + return f end - return f end end