From c694f07985200c78e1e645b732fffe5abe4960cf Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sun, 4 Jan 2026 13:35:59 -0800 Subject: faster sort --- main.lua | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'main.lua') diff --git a/main.lua b/main.lua index 074cd05..cfb0b9c 100644 --- a/main.lua +++ b/main.lua @@ -178,25 +178,26 @@ local function push_menu(t) end local function sort_options(options) - table.sort(options, function(a, b) - local a_name = a.name - local b_name = b.name - - if favourites[a.id] then - a_name = '\0\0' .. a_name + local scores = {} + for _, v in ipairs(options) do + local score = 0 + if favourites[v.id] then + score = score + 2 end - if a.type == 'group' and a.group_type ~= 'series' then - a_name = '\0' .. a_name + if v.type == 'group' and v.group_type ~= 'series' then + score = score + 1 end + scores[v] = score + end - if favourites[b.id] then - b_name = '\0\0' .. b_name - end - if b.type == 'group' and b.group_type ~= 'series' then - b_name = '\0' .. b_name + table.sort(options, function(a, b) + local sa = scores[a] + local sb = scores[b] + if sa ~= sb then + return sa > sb + else + return a.name < b.name end - - return a_name < b_name end) end -- cgit v1.2.3-70-g09d2