Skip to content

Commit

Permalink
perf(state): sort_pins_left in place
Browse files Browse the repository at this point in the history
This is a 5–10× improvement, depending on the current layout of the
bufferline.
  • Loading branch information
Iron-E committed Apr 5, 2023
1 parent c7e0f9c commit 7a3a4b6
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lua/barbar/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ local json_encode = vim.json.encode --- @type function
local json_decode = vim.json.decode --- @type function
local get_current_buf = vim.api.nvim_get_current_buf --- @type function
local list_bufs = vim.api.nvim_list_bufs --- @type function
local list_extend = vim.list_extend
local list_slice = vim.list_slice
local tbl_contains = vim.tbl_contains
local tbl_filter = vim.tbl_filter
Expand Down Expand Up @@ -120,18 +119,17 @@ end
--- Sort the pinned tabs to the left of the bufferline.
--- @return nil
function state.sort_pins_to_left()
local unpinned = {}
local pinned = 0

local i = 1
while i <= #state.buffers do
local i = #state.buffers
while i >= 1 + pinned do
if state.is_pinned(state.buffers[i]) then
i = i + 1
table_insert(state.buffers, 1, table_remove(state.buffers, i))
pinned = pinned + 1
else
table_insert(unpinned, table_remove(state.buffers, i))
i = i - 1
end
end

state.buffers = list_extend(state.buffers, unpinned)
end

--- Toggle the `bufnr`'s "pin" state.
Expand Down

0 comments on commit 7a3a4b6

Please sign in to comment.