mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
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:
@@ -1123,7 +1123,7 @@ static void command_line_scan(mparm_T *parmp)
|
||||
} else if (STRNICMP(argv[0] + argv_idx, "clean", 5) == 0) {
|
||||
parmp->use_vimrc = "NONE";
|
||||
parmp->clean = true;
|
||||
set_option_value_give_err("shadafile", STATIC_CSTR_AS_OPTVAL("NONE"), 0);
|
||||
set_option_value_give_err(kOptShadafile, STATIC_CSTR_AS_OPTVAL("NONE"), 0);
|
||||
} else if (STRNICMP(argv[0] + argv_idx, "luamod-dev", 9) == 0) {
|
||||
nlua_disable_preload = true;
|
||||
} else {
|
||||
@@ -1137,7 +1137,7 @@ static void command_line_scan(mparm_T *parmp)
|
||||
}
|
||||
break;
|
||||
case 'A': // "-A" start in Arabic mode.
|
||||
set_option_value_give_err("arabic", BOOLEAN_OPTVAL(true), 0);
|
||||
set_option_value_give_err(kOptArabic, BOOLEAN_OPTVAL(true), 0);
|
||||
break;
|
||||
case 'b': // "-b" binary mode.
|
||||
// Needs to be effective before expanding file names, because
|
||||
@@ -1167,8 +1167,8 @@ static void command_line_scan(mparm_T *parmp)
|
||||
usage();
|
||||
os_exit(0);
|
||||
case 'H': // "-H" start in Hebrew mode: rl + keymap=hebrew set.
|
||||
set_option_value_give_err("keymap", STATIC_CSTR_AS_OPTVAL("hebrew"), 0);
|
||||
set_option_value_give_err("rl", BOOLEAN_OPTVAL(true), 0);
|
||||
set_option_value_give_err(kOptKeymap, STATIC_CSTR_AS_OPTVAL("hebrew"), 0);
|
||||
set_option_value_give_err(kOptRightleft, BOOLEAN_OPTVAL(true), 0);
|
||||
break;
|
||||
case 'M': // "-M" no changes or writing of files
|
||||
reset_modifiable();
|
||||
@@ -1248,7 +1248,7 @@ static void command_line_scan(mparm_T *parmp)
|
||||
// default is 10: a little bit verbose
|
||||
p_verbose = get_number_arg(argv[0], &argv_idx, 10);
|
||||
if (argv[0][argv_idx] != NUL) {
|
||||
set_option_value_give_err("verbosefile", CSTR_AS_OPTVAL(argv[0] + argv_idx), 0);
|
||||
set_option_value_give_err(kOptVerbosefile, CSTR_AS_OPTVAL(argv[0] + argv_idx), 0);
|
||||
argv_idx = (int)strlen(argv[0]);
|
||||
}
|
||||
break;
|
||||
@@ -1256,7 +1256,7 @@ static void command_line_scan(mparm_T *parmp)
|
||||
// "-w {scriptout}" write to script
|
||||
if (ascii_isdigit((argv[0])[argv_idx])) {
|
||||
n = get_number_arg(argv[0], &argv_idx, 10);
|
||||
set_option_value_give_err("window", NUMBER_OPTVAL((OptInt)n), 0);
|
||||
set_option_value_give_err(kOptWindow, NUMBER_OPTVAL((OptInt)n), 0);
|
||||
break;
|
||||
}
|
||||
want_argument = true;
|
||||
@@ -1352,7 +1352,7 @@ static void command_line_scan(mparm_T *parmp)
|
||||
break;
|
||||
|
||||
case 'i': // "-i {shada}" use for shada
|
||||
set_option_value_give_err("shadafile", CSTR_AS_OPTVAL(argv[0]), 0);
|
||||
set_option_value_give_err(kOptShadafile, CSTR_AS_OPTVAL(argv[0]), 0);
|
||||
break;
|
||||
|
||||
case 'l': // "-l" Lua script: args after "-l".
|
||||
@@ -1362,7 +1362,7 @@ static void command_line_scan(mparm_T *parmp)
|
||||
parmp->no_swap_file = true;
|
||||
parmp->use_vimrc = parmp->use_vimrc ? parmp->use_vimrc : "NONE";
|
||||
if (p_shadafile == NULL || *p_shadafile == NUL) {
|
||||
set_option_value_give_err("shadafile", STATIC_CSTR_AS_OPTVAL("NONE"), 0);
|
||||
set_option_value_give_err(kOptShadafile, STATIC_CSTR_AS_OPTVAL("NONE"), 0);
|
||||
}
|
||||
parmp->luaf = argv[0];
|
||||
argc--;
|
||||
@@ -1398,7 +1398,7 @@ scripterror:
|
||||
if (ascii_isdigit(*(argv[0]))) {
|
||||
argv_idx = 0;
|
||||
n = get_number_arg(argv[0], &argv_idx, 10);
|
||||
set_option_value_give_err("window", NUMBER_OPTVAL((OptInt)n), 0);
|
||||
set_option_value_give_err(kOptWindow, NUMBER_OPTVAL((OptInt)n), 0);
|
||||
argv_idx = -1;
|
||||
break;
|
||||
}
|
||||
@@ -1549,7 +1549,7 @@ static void handle_quickfix(mparm_T *paramp)
|
||||
{
|
||||
if (paramp->edit_type == EDIT_QF) {
|
||||
if (paramp->use_ef != NULL) {
|
||||
set_string_option_direct("ef", -1, paramp->use_ef, OPT_FREE, SID_CARG);
|
||||
set_string_option_direct(kOptErrorfile, paramp->use_ef, OPT_FREE, SID_CARG);
|
||||
}
|
||||
vim_snprintf(IObuff, IOSIZE, "cfile %s", p_ef);
|
||||
if (qf_init(NULL, p_ef, p_efm, true, IObuff, p_menc) < 0) {
|
||||
@@ -1794,7 +1794,7 @@ static void edit_buffers(mparm_T *parmp, char *cwd)
|
||||
|
||||
p_shm_save = xstrdup(p_shm);
|
||||
snprintf(buf, sizeof(buf), "F%s", p_shm);
|
||||
set_option_value_give_err("shm", CSTR_AS_OPTVAL(buf), 0);
|
||||
set_option_value_give_err(kOptShortmess, CSTR_AS_OPTVAL(buf), 0);
|
||||
}
|
||||
} else {
|
||||
if (curwin->w_next == NULL) { // just checking
|
||||
@@ -1839,7 +1839,7 @@ static void edit_buffers(mparm_T *parmp, char *cwd)
|
||||
}
|
||||
|
||||
if (p_shm_save != NULL) {
|
||||
set_option_value_give_err("shm", CSTR_AS_OPTVAL(p_shm_save), 0);
|
||||
set_option_value_give_err(kOptShortmess, CSTR_AS_OPTVAL(p_shm_save), 0);
|
||||
xfree(p_shm_save);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user