aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/deprecated.c
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@proton.me>2023-12-07 23:46:57 +0600
committerFamiu Haque <famiuhaque@proton.me>2023-12-09 17:54:43 +0600
commit6346987601a28b00564295ee8be0a8b00d9ff911 (patch)
treeb50f5f4f41a7262434d1c223c97e309eea243ff1 /src/nvim/api/deprecated.c
parent29aa4dd10af74d29891cb293dc9ff393e9dba11f (diff)
downloadrneovim-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/api/deprecated.c')
-rw-r--r--src/nvim/api/deprecated.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c
index d6a76617a7..34bf029483 100644
--- a/src/nvim/api/deprecated.c
+++ b/src/nvim/api/deprecated.c
@@ -643,7 +643,7 @@ static Object get_option_from(void *from, OptReqScope req_scope, String name, Er
return (Object)OBJECT_INIT;
});
- OptVal value = get_option_value_strict(name.data, req_scope, from, err);
+ OptVal value = get_option_value_strict(findoption(name.data), req_scope, from, err);
if (ERROR_SET(err)) {
return (Object)OBJECT_INIT;
}
@@ -669,8 +669,8 @@ static void set_option_to(uint64_t channel_id, void *to, OptReqScope req_scope,
return;
});
- int flags = get_option_attrs(name.data);
- VALIDATE_S(flags != 0, "option name", name.data, {
+ int opt_idx = findoption(name.data);
+ VALIDATE_S(opt_idx >= 0, "option name", name.data, {
return;
});
@@ -685,13 +685,14 @@ static void set_option_to(uint64_t channel_id, void *to, OptReqScope req_scope,
return;
});
+ int attrs = get_option_attrs(opt_idx);
// For global-win-local options -> setlocal
// For win-local options -> setglobal and setlocal (opt_flags == 0)
- const int opt_flags = (req_scope == kOptReqWin && !(flags & SOPT_GLOBAL))
+ const int opt_flags = (req_scope == kOptReqWin && !(attrs & SOPT_GLOBAL))
? 0
: (req_scope == kOptReqGlobal) ? OPT_GLOBAL : OPT_LOCAL;
WITH_SCRIPT_CONTEXT(channel_id, {
- set_option_value_for(name.data, optval, opt_flags, req_scope, to, err);
+ set_option_value_for(name.data, opt_idx, optval, opt_flags, req_scope, to, err);
});
}