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/help.c | |
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/help.c')
-rw-r--r-- | src/nvim/help.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nvim/help.c b/src/nvim/help.c index dc4f6c44ff..28b95b2346 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -608,7 +608,7 @@ void cleanup_help_tags(int num_file, char **file) void prepare_help_buffer(void) { curbuf->b_help = true; - set_string_option_direct("buftype", -1, "help", OPT_FREE|OPT_LOCAL, 0); + set_string_option_direct(kOptBuftype, "help", OPT_FREE|OPT_LOCAL, 0); // Always set these options after jumping to a help tag, because the // user may have an autocommand that gets in the way. @@ -617,13 +617,13 @@ void prepare_help_buffer(void) // Only set it when needed, buf_init_chartab() is some work. char *p = "!-~,^*,^|,^\",192-255"; if (strcmp(curbuf->b_p_isk, p) != 0) { - set_string_option_direct("isk", -1, p, OPT_FREE|OPT_LOCAL, 0); + set_string_option_direct(kOptIskeyword, p, OPT_FREE|OPT_LOCAL, 0); check_buf_options(curbuf); (void)buf_init_chartab(curbuf, false); } // Don't use the global foldmethod. - set_string_option_direct("fdm", -1, "manual", OPT_FREE|OPT_LOCAL, 0); + set_string_option_direct(kOptFoldmethod, "manual", OPT_FREE|OPT_LOCAL, 0); curbuf->b_p_ts = 8; // 'tabstop' is 8. curwin->w_p_list = false; // No list mode. @@ -649,7 +649,7 @@ void fix_help_buffer(void) // Set filetype to "help". if (strcmp(curbuf->b_p_ft, "help") != 0) { curbuf->b_ro_locked++; - set_option_value_give_err("ft", STATIC_CSTR_AS_OPTVAL("help"), OPT_LOCAL); + set_option_value_give_err(kOptFiletype, STATIC_CSTR_AS_OPTVAL("help"), OPT_LOCAL); curbuf->b_ro_locked--; } |