diff options
author | Riley Bruins <ribru17@hotmail.com> | 2024-06-14 17:54:10 -0700 |
---|---|---|
committer | Christian Clason <c.clason@uni-graz.at> | 2024-06-24 14:10:25 +0200 |
commit | c57a85e0eda067ea28ca5853358947332aceecfd (patch) | |
tree | db674dfec340ebc2a1e4d9c665841181e91e9aac /runtime/lua/vim/treesitter/_fold.lua | |
parent | 0a789a81821343c8287219b646c787435567a2be (diff) | |
download | rneovim-c57a85e0eda067ea28ca5853358947332aceecfd.tar.gz rneovim-c57a85e0eda067ea28ca5853358947332aceecfd.tar.bz2 rneovim-c57a85e0eda067ea28ca5853358947332aceecfd.zip |
perf(treesitter): remove unnecessary foldexpr loop
Instead of looping over all captured nodes, just take the end range from
the last node in the list. This uses the fact that nodes returned by
iter_matches are ordered by their range (earlier to later).
Diffstat (limited to 'runtime/lua/vim/treesitter/_fold.lua')
-rw-r--r-- | runtime/lua/vim/treesitter/_fold.lua | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/runtime/lua/vim/treesitter/_fold.lua b/runtime/lua/vim/treesitter/_fold.lua index b8f1ef1282..194e09babc 100644 --- a/runtime/lua/vim/treesitter/_fold.lua +++ b/runtime/lua/vim/treesitter/_fold.lua @@ -139,16 +139,12 @@ local function compute_folds_levels(bufnr, info, srow, erow, parse_injections) local range = ts.get_range(nodes[1], bufnr, metadata[id]) local start, _, stop, stop_col = Range.unpack4(range) - for i = 2, #nodes, 1 do - local node_range = ts.get_range(nodes[i], bufnr, metadata[id]) - local node_start, _, node_stop, node_stop_col = Range.unpack4(node_range) - if node_start < start then - start = node_start - end - if node_stop > stop then - stop = node_stop - stop_col = node_stop_col - end + if #nodes > 1 then + -- assumes nodes are ordered by range + local end_range = ts.get_range(nodes[#nodes], bufnr, metadata[id]) + local _, _, end_stop, end_stop_col = Range.unpack4(end_range) + stop = end_stop + stop_col = end_stop_col end if stop_col == 0 then |