diff options
author | Famiu Haque <famiuhaque@proton.me> | 2023-12-07 23:46:57 +0600 |
---|---|---|
committer | Famiu Haque <famiuhaque@proton.me> | 2023-12-09 17:54:43 +0600 |
commit | 6346987601a28b00564295ee8be0a8b00d9ff911 (patch) | |
tree | b50f5f4f41a7262434d1c223c97e309eea243ff1 /src/nvim/generators/gen_options.lua | |
parent | 29aa4dd10af74d29891cb293dc9ff393e9dba11f (diff) | |
download | rneovim-6346987601a28b00564295ee8be0a8b00d9ff911.tar.gz rneovim-6346987601a28b00564295ee8be0a8b00d9ff911.tar.bz2 rneovim-6346987601a28b00564295ee8be0a8b00d9ff911.zip |
refactor(options): reduce `findoption()` usage
Problem: Many places in the code use `findoption()` to access an option using its name, even if the option index is available. This is very slow because it requires looping through the options array over and over.
Solution: Use option index instead of name wherever possible. Also introduce an `OptIndex` enum which contains the index for every option as enum constants, this eliminates the need to pass static option names as strings.
Diffstat (limited to 'src/nvim/generators/gen_options.lua')
-rw-r--r-- | src/nvim/generators/gen_options.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 3a355634f3..2b17add7ba 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -1,4 +1,5 @@ local options_file = arg[1] +local options_enum_file = arg[2] local opt_fd = assert(io.open(options_file, 'w')) @@ -41,6 +42,12 @@ local list_flags = { flagscomma = 'P_COMMA|P_FLAGLIST', } +--- @param s string +--- @return string +local title_case = function(s) + return s:sub(1, 1):upper() .. s:sub(2):lower() +end + --- @param o vim.option_meta --- @return string local function get_flags(o) @@ -229,4 +236,14 @@ w('') for _, v in ipairs(defines) do w('#define ' .. v[1] .. ' ' .. v[2]) end + +-- Generate options enum file +opt_fd = assert(io.open(options_enum_file, 'w')) + +w('typedef enum {') +for i, o in ipairs(options.options) do + w((' kOpt%s = %u,'):format(title_case(o.full_name), i - 1)) +end +w('} OptIndex;') + opt_fd:close() |