summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-04 13:35:59 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-04 13:35:59 -0800
commitc694f07985200c78e1e645b732fffe5abe4960cf (patch)
tree9f5aa9d43e42e84a817fc3e8059f1eb140575ba1
parentbb08ce440878522cd02a80e27de7f3e313b0ca00 (diff)
downloadmpv-iptv-menu-c694f07985200c78e1e645b732fffe5abe4960cf.tar.gz
mpv-iptv-menu-c694f07985200c78e1e645b732fffe5abe4960cf.tar.xz
faster sort
-rw-r--r--main.lua31
1 files changed, 16 insertions, 15 deletions
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