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

@@ -1617,7 +1617,7 @@ failed:
save_file_ff(curbuf);
// If editing a new file: set 'fenc' for the current buffer.
// Also for ":read ++edit file".
set_string_option_direct("fenc", -1, fenc, OPT_FREE | OPT_LOCAL, 0);
set_string_option_direct(kOptFileencoding, fenc, OPT_FREE | OPT_LOCAL, 0);
}
if (fenc_alloced) {
xfree(fenc);
@@ -1965,7 +1965,7 @@ void set_forced_fenc(exarg_T *eap)
}
char *fenc = enc_canonize(eap->cmd + eap->force_enc);
set_string_option_direct("fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0);
set_string_option_direct(kOptFileencoding, fenc, OPT_FREE|OPT_LOCAL, 0);
xfree(fenc);
}