From 7141109816b361d8c4d4c152fbdff1ccfdbda4dc Mon Sep 17 00:00:00 2001 From: pynappo Date: Mon, 13 Oct 2025 18:47:54 -0700 Subject: [PATCH 1/3] faster path split --- lua/neo-tree/utils/init.lua | 56 ++++++++++++++++++++++++++---- tests/neo-tree/utils/path_spec.lua | 1 + 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/lua/neo-tree/utils/init.lua b/lua/neo-tree/utils/init.lua index 1296504b..c927ce04 100644 --- a/lua/neo-tree/utils/init.lua +++ b/lua/neo-tree/utils/init.lua @@ -1128,6 +1128,54 @@ M.split_path = function(path) if prefix and vim.startswith(prefix, path) then return nil, path end + + -- this is more than just a root path + if path:sub(-1) == M.path_separator then + -- trim it off + path = path:sub(1, -2) + end + + -- old + -- local rest_parts = vim.split(rest_of_path, M.path_separator, { plain = true }) + -- local name = table.remove(rest_parts) + -- local parentPath = (prefix or "") .. table.concat(rest_parts, M.path_separator) + + local last_separator_index + local i = prefix and #prefix + 1 or 1 + local j + repeat + j = path:find(M.path_separator, i, true) + if j then + last_separator_index = j + i = j + 1 + end + until not j + + if not last_separator_index then + if not prefix then + return nil, path + end + return prefix, path:sub(#prefix + 1) + end + + local parent_path = path:sub(1, last_separator_index - 1) + local tail = path:sub(last_separator_index + 1) + return parent_path, tail +end + +M.split_path_old = function(path) + if not path then + return nil, nil + end + if M.is_windows then + path = M.windowize_path(path) + end + local prefix = M.abspath_prefix(path) + if prefix and vim.startswith(prefix, path) then + return nil, path + end + + -- this is more than just a root path if path:sub(-1) == M.path_separator then -- trim it off path = path:sub(1, -2) @@ -1136,13 +1184,9 @@ M.split_path = function(path) local rest_of_path = prefix and path:sub(#prefix + 1) or path local rest_parts = vim.split(rest_of_path, M.path_separator, { plain = true }) local name = table.remove(rest_parts) - local parentPath = (prefix or "") .. table.concat(rest_parts, M.path_separator) - - if #parentPath == 0 then - return prefix, name - end + local parent_path = (prefix or "") .. table.concat(rest_parts, M.path_separator) - return parentPath, name + return parent_path, name end ---Joins arbitrary number of paths together. diff --git a/tests/neo-tree/utils/path_spec.lua b/tests/neo-tree/utils/path_spec.lua index ffda1b74..d7e0834a 100644 --- a/tests/neo-tree/utils/path_spec.lua +++ b/tests/neo-tree/utils/path_spec.lua @@ -104,6 +104,7 @@ describe("utils path functions", function() -- Absolute paths assert.are.same({ "/a", "b" }, { utils.split_path("/a/b") }) + assert.are.same({ "/a/b/c/d", "e" }, { utils.split_path("/a/b/c/d/e") }) assert.are.same({ "/", "a" }, { utils.split_path("/a") }) -- Edge cases From ca9f43ed1784487fbbdaa9278845dd71caf5b055 Mon Sep 17 00:00:00 2001 From: pynappo Date: Mon, 13 Oct 2025 18:48:44 -0700 Subject: [PATCH 2/3] remove old --- lua/neo-tree/utils/init.lua | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/lua/neo-tree/utils/init.lua b/lua/neo-tree/utils/init.lua index c927ce04..c626ffef 100644 --- a/lua/neo-tree/utils/init.lua +++ b/lua/neo-tree/utils/init.lua @@ -1163,32 +1163,6 @@ M.split_path = function(path) return parent_path, tail end -M.split_path_old = function(path) - if not path then - return nil, nil - end - if M.is_windows then - path = M.windowize_path(path) - end - local prefix = M.abspath_prefix(path) - if prefix and vim.startswith(prefix, path) then - return nil, path - end - - -- this is more than just a root path - if path:sub(-1) == M.path_separator then - -- trim it off - path = path:sub(1, -2) - end - - local rest_of_path = prefix and path:sub(#prefix + 1) or path - local rest_parts = vim.split(rest_of_path, M.path_separator, { plain = true }) - local name = table.remove(rest_parts) - local parent_path = (prefix or "") .. table.concat(rest_parts, M.path_separator) - - return parent_path, name -end - ---Joins arbitrary number of paths together. ---@param ... string The paths to join. ---@return string From 6d0bc7825e810717fe59f78c10e0affba35bba30 Mon Sep 17 00:00:00 2001 From: pynappo Date: Mon, 13 Oct 2025 18:54:43 -0700 Subject: [PATCH 3/3] Remove comment --- lua/neo-tree/utils/init.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lua/neo-tree/utils/init.lua b/lua/neo-tree/utils/init.lua index c626ffef..2550b887 100644 --- a/lua/neo-tree/utils/init.lua +++ b/lua/neo-tree/utils/init.lua @@ -1135,11 +1135,6 @@ M.split_path = function(path) path = path:sub(1, -2) end - -- old - -- local rest_parts = vim.split(rest_of_path, M.path_separator, { plain = true }) - -- local name = table.remove(rest_parts) - -- local parentPath = (prefix or "") .. table.concat(rest_parts, M.path_separator) - local last_separator_index local i = prefix and #prefix + 1 or 1 local j