diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-06-04 11:08:25 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-06-05 00:11:57 +0200 |
commit | 545dc82c1b22709c83ec23e9450f245f9ff1babc (patch) | |
tree | 5e0fa2319898925d7536cd36160987e2668dcf8f /runtime/lua/vim/_meta.lua | |
parent | df4ffce543ba0d4e2464b3978f4e66eaddf6a29a (diff) | |
download | rneovim-545dc82c1b22709c83ec23e9450f245f9ff1babc.tar.gz rneovim-545dc82c1b22709c83ec23e9450f245f9ff1babc.tar.bz2 rneovim-545dc82c1b22709c83ec23e9450f245f9ff1babc.zip |
perf(tests): don't invoke nvim_get_all_options_info until needed
This call alone is responible of 40 000 000 out of 80 000 000
individual alloc/free calls in the test suite.
Diffstat (limited to 'runtime/lua/vim/_meta.lua')
-rw-r--r-- | runtime/lua/vim/_meta.lua | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index 1706956bca..59cf837a1d 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -10,29 +10,39 @@ local SET_TYPES = setmetatable({ GLOBAL = 2, }, { __index = error }) -local options_info = {} -for _, v in pairs(a.nvim_get_all_options_info()) do - options_info[v.name] = v - if v.shortname ~= '' then - options_info[v.shortname] = v +local options_info = nil +local buf_options = nil +local glb_options = nil +local win_options = nil + +local function _setup() + if options_info ~= nil then + return + end + options_info = {} + for _, v in pairs(a.nvim_get_all_options_info()) do + options_info[v.name] = v + if v.shortname ~= '' then + options_info[v.shortname] = v + end end -end -local get_scoped_options = function(scope) - local result = {} - for name, option_info in pairs(options_info) do - if option_info.scope == scope then - result[name] = true + local function get_scoped_options(scope) + local result = {} + for name, option_info in pairs(options_info) do + if option_info.scope == scope then + result[name] = true + end end + + return result end - return result + buf_options = get_scoped_options('buf') + glb_options = get_scoped_options('global') + win_options = get_scoped_options('win') end -local buf_options = get_scoped_options('buf') -local glb_options = get_scoped_options('global') -local win_options = get_scoped_options('win') - local function make_meta_accessor(get, set, del, validator) validator = validator or function() return true @@ -90,6 +100,7 @@ do -- buffer option accessor return make_meta_accessor(get, set, nil, function(k) if type(k) == 'string' then + _setup() if win_options[k] then error(string.format([['%s' is a window option, not a buffer option. See ":help %s"]], k, k)) elseif glb_options[k] then @@ -119,6 +130,7 @@ do -- window option accessor return make_meta_accessor(get, set, nil, function(k) if type(k) == 'string' then + _setup() if buf_options[k] then error(string.format([['%s' is a buffer option, not a window option. See ":help %s"]], k, k)) elseif glb_options[k] then @@ -610,6 +622,7 @@ local create_option_metatable = function(set_type) local set_mt, option_mt local make_option = function(name, value) + _setup() local info = assert(options_info[name], 'Not a valid option name: ' .. name) if type(value) == 'table' and getmetatable(value) == option_mt then |