diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-27 01:12:16 -0800 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-01-27 01:16:58 -0800 |
| commit | 82526665364389d92e0f2c33eba04678275863bb (patch) | |
| tree | 547f3a797b861e85c79bde7baf87fe5145c0396d /state.lua | |
| parent | 1d2c82bfb4dcfd71045f2948bb320a94013971a5 (diff) | |
| download | mpv-iptv-menu-82526665364389d92e0f2c33eba04678275863bb.tar.gz mpv-iptv-menu-82526665364389d92e0f2c33eba04678275863bb.tar.xz | |
on-demand calculation and update of option info
Using metatables to calculate info strings on render, we can avoid
precomputing it for all options when generating the menu, making certain
menus open much faster. This also allows us to update dynamic info, e.g.
the currently programme, while the menu is open.
Diffstat (limited to 'state.lua')
| -rw-r--r-- | state.lua | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -167,7 +167,7 @@ function menu_mt:update_search_matches() local options = {} for _, v in ipairs(self.search_options) do - local matches = {} + local matches local name = v.name if not case_sensitive then @@ -180,13 +180,17 @@ function menu_mt:update_search_matches() if not i then break end + matches = matches or {} matches[#matches+1] = {start = i, stop = j} end - if #matches > 0 then - local t = util.copy_table(v) - t.matches = matches - options[#options+1] = t + if matches then + -- search options may contain dynamic data that is + -- updated on redraw. using a proxy table instead of + -- copying prevents potential updates on every change + -- of search text. + options[#options+1] = setmetatable( + {matches = matches}, {__index = v}) end end |
