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

@@ -948,8 +948,8 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err)
buf_copy_options(buf, BCO_ENTER | BCO_NOHELP);
if (scratch) {
set_string_option_direct_in_buf(buf, "bufhidden", -1, "hide", OPT_LOCAL, 0);
set_string_option_direct_in_buf(buf, "buftype", -1, "nofile", OPT_LOCAL, 0);
set_string_option_direct_in_buf(buf, kOptBufhidden, "hide", OPT_LOCAL, 0);
set_string_option_direct_in_buf(buf, kOptBuftype, "nofile", OPT_LOCAL, 0);
assert(buf->b_ml.ml_mfp->mf_fd < 0); // ml_open() should not have opened swapfile already
buf->b_p_swf = false;
buf->b_p_ml = false;
@@ -2239,7 +2239,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error *
buf,
sizeof(buf),
str.data,
NULL,
-1,
0,
fillchar,
maxwidth,