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.
This commit is contained in:
Famiu Haque
2023-12-07 23:46:57 +06:00
parent 29aa4dd10a
commit 6346987601
39 changed files with 336 additions and 352 deletions

View File

@@ -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--;
}