mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -10,7 +10,16 @@ local SET_TYPES = setmetatable({ | |||||||
|   GLOBAL = 2, |   GLOBAL = 2, | ||||||
| }, { __index = error }) | }, { __index = error }) | ||||||
|  |  | ||||||
| local options_info = {} | 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 |   for _, v in pairs(a.nvim_get_all_options_info()) do | ||||||
|     options_info[v.name] = v |     options_info[v.name] = v | ||||||
|     if v.shortname ~= '' then |     if v.shortname ~= '' then | ||||||
| @@ -18,7 +27,7 @@ for _, v in pairs(a.nvim_get_all_options_info()) do | |||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
| local get_scoped_options = function(scope) |   local function get_scoped_options(scope) | ||||||
|     local result = {} |     local result = {} | ||||||
|     for name, option_info in pairs(options_info) do |     for name, option_info in pairs(options_info) do | ||||||
|       if option_info.scope == scope then |       if option_info.scope == scope then | ||||||
| @@ -29,9 +38,10 @@ local get_scoped_options = function(scope) | |||||||
|     return result |     return result | ||||||
|   end |   end | ||||||
|  |  | ||||||
| local buf_options = get_scoped_options('buf') |   buf_options = get_scoped_options('buf') | ||||||
| local glb_options = get_scoped_options('global') |   glb_options = get_scoped_options('global') | ||||||
| local win_options = get_scoped_options('win') |   win_options = get_scoped_options('win') | ||||||
|  | end | ||||||
|  |  | ||||||
| local function make_meta_accessor(get, set, del, validator) | local function make_meta_accessor(get, set, del, validator) | ||||||
|   validator = validator or function() |   validator = validator or function() | ||||||
| @@ -90,6 +100,7 @@ do -- buffer option accessor | |||||||
|  |  | ||||||
|     return make_meta_accessor(get, set, nil, function(k) |     return make_meta_accessor(get, set, nil, function(k) | ||||||
|       if type(k) == 'string' then |       if type(k) == 'string' then | ||||||
|  |         _setup() | ||||||
|         if win_options[k] then |         if win_options[k] then | ||||||
|           error(string.format([['%s' is a window option, not a buffer option. See ":help %s"]], k, k)) |           error(string.format([['%s' is a window option, not a buffer option. See ":help %s"]], k, k)) | ||||||
|         elseif glb_options[k] then |         elseif glb_options[k] then | ||||||
| @@ -119,6 +130,7 @@ do -- window option accessor | |||||||
|  |  | ||||||
|     return make_meta_accessor(get, set, nil, function(k) |     return make_meta_accessor(get, set, nil, function(k) | ||||||
|       if type(k) == 'string' then |       if type(k) == 'string' then | ||||||
|  |         _setup() | ||||||
|         if buf_options[k] then |         if buf_options[k] then | ||||||
|           error(string.format([['%s' is a buffer option, not a window option. See ":help %s"]], k, k)) |           error(string.format([['%s' is a buffer option, not a window option. See ":help %s"]], k, k)) | ||||||
|         elseif glb_options[k] then |         elseif glb_options[k] then | ||||||
| @@ -610,6 +622,7 @@ local create_option_metatable = function(set_type) | |||||||
|   local set_mt, option_mt |   local set_mt, option_mt | ||||||
|  |  | ||||||
|   local make_option = function(name, value) |   local make_option = function(name, value) | ||||||
|  |     _setup() | ||||||
|     local info = assert(options_info[name], 'Not a valid option name: ' .. name) |     local info = assert(options_info[name], 'Not a valid option name: ' .. name) | ||||||
|  |  | ||||||
|     if type(value) == 'table' and getmetatable(value) == option_mt then |     if type(value) == 'table' and getmetatable(value) == option_mt then | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 bfredl
					bfredl