Skip to content

Commit

Permalink
patch 9.0.2154: The option[] array is not sorted
Browse files Browse the repository at this point in the history
Problem:  The options[] array is not sorted alphabetically.
Solution: Sort it alphabetically.  Add a test.  Avoid unnecessary loop
          iterations in findoption().

closes: #13648

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
zeertzjq authored and chrisbra committed Dec 8, 2023
1 parent ff0baca commit f48558e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 79 deletions.
4 changes: 3 additions & 1 deletion src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -4933,11 +4933,13 @@ findoption(char_u *arg)
opt_idx = quick_tab[26];
else
opt_idx = quick_tab[CharOrdLow(arg[0])];
for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
for (; (s = options[opt_idx].fullname) != NULL && s[0] == arg[0]; opt_idx++)
{
if (STRCMP(arg, s) == 0) // match full name
break;
}
if (s != NULL && s[0] != arg[0])
s = NULL;
if (s == NULL && !is_term_opt)
{
opt_idx = quick_tab[CharOrdLow(arg[0])];
Expand Down
156 changes: 78 additions & 78 deletions src/optiondefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,6 @@ static struct vimoption options[] =
(char_u *)NULL, PV_NONE, NULL, NULL,
{(char_u *)FALSE, (char_u *)FALSE}
SCTX_INIT},
{"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
#ifdef FEAT_ARABIC
(char_u *)VAR_WIN, PV_ARAB, did_set_arabic, NULL,
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
#endif
{(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
{"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
#ifdef FEAT_ARABIC
(char_u *)&p_arshape, PV_NONE, NULL, NULL,
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
#endif
{(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
{"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
#ifdef FEAT_RIGHTLEFT
(char_u *)&p_ari, PV_NONE, NULL, NULL,
Expand All @@ -369,18 +355,23 @@ static struct vimoption options[] =
(char_u *)&p_ambw, PV_NONE, did_set_ambiwidth, expand_set_ambiwidth,
{(char_u *)"single", (char_u *)0L}
SCTX_INIT},
{"autochdir", "acd", P_BOOL|P_VI_DEF,
#ifdef FEAT_AUTOCHDIR
(char_u *)&p_acd, PV_NONE, did_set_autochdir, NULL,
{(char_u *)FALSE, (char_u *)0L}
{"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
#ifdef FEAT_ARABIC
(char_u *)VAR_WIN, PV_ARAB, did_set_arabic, NULL,
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
{(char_u *)0L, (char_u *)0L}
#endif
SCTX_INIT},
{"autoshelldir", "asd", P_BOOL|P_VI_DEF,
#ifdef FEAT_AUTOSHELLDIR
(char_u *)&p_asd, PV_NONE, NULL, NULL,
{(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
{"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
#ifdef FEAT_ARABIC
(char_u *)&p_arshape, PV_NONE, NULL, NULL,
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
#endif
{(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
{"autochdir", "acd", P_BOOL|P_VI_DEF,
#ifdef FEAT_AUTOCHDIR
(char_u *)&p_acd, PV_NONE, did_set_autochdir, NULL,
{(char_u *)FALSE, (char_u *)0L}
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
Expand All @@ -396,6 +387,15 @@ static struct vimoption options[] =
{"autoread", "ar", P_BOOL|P_VI_DEF,
(char_u *)&p_ar, PV_AR, NULL, NULL,
{(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
{"autoshelldir", "asd", P_BOOL|P_VI_DEF,
#ifdef FEAT_AUTOSHELLDIR
(char_u *)&p_asd, PV_NONE, NULL, NULL,
{(char_u *)FALSE, (char_u *)0L}
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
{(char_u *)0L, (char_u *)0L}
#endif
SCTX_INIT},
{"autowrite", "aw", P_BOOL|P_VI_DEF,
(char_u *)&p_aw, PV_NONE, NULL, NULL,
{(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Expand Down Expand Up @@ -643,23 +643,6 @@ static struct vimoption options[] =
(char_u *)&p_cpt, PV_CPT, did_set_complete, expand_set_complete,
{(char_u *)".,w,b,u,t,i", (char_u *)0L}
SCTX_INIT},
{"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF|P_FLAGLIST,
#ifdef FEAT_CONCEAL
(char_u *)VAR_WIN, PV_COCU, did_set_concealcursor, expand_set_concealcursor,
{(char_u *)"", (char_u *)NULL}
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
{(char_u *)NULL, (char_u *)0L}
#endif
SCTX_INIT},
{"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
#ifdef FEAT_CONCEAL
(char_u *)VAR_WIN, PV_COLE, did_set_conceallevel, NULL,
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
#endif
{(char_u *)0L, (char_u *)0L}
SCTX_INIT},
{"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE|P_FUNC,
#ifdef FEAT_COMPL_FUNC
(char_u *)&p_cfu, PV_CFU, did_set_completefunc, NULL,
Expand Down Expand Up @@ -691,6 +674,23 @@ static struct vimoption options[] =
{(char_u *)0L, (char_u *)0L}
#endif
SCTX_INIT},
{"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF|P_FLAGLIST,
#ifdef FEAT_CONCEAL
(char_u *)VAR_WIN, PV_COCU, did_set_concealcursor, expand_set_concealcursor,
{(char_u *)"", (char_u *)NULL}
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
{(char_u *)NULL, (char_u *)0L}
#endif
SCTX_INIT},
{"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
#ifdef FEAT_CONCEAL
(char_u *)VAR_WIN, PV_COLE, did_set_conceallevel, NULL,
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
#endif
{(char_u *)0L, (char_u *)0L}
SCTX_INIT},
{"confirm", "cf", P_BOOL|P_VI_DEF,
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
(char_u *)&p_confirm, PV_NONE, NULL, NULL,
Expand Down Expand Up @@ -1091,14 +1091,14 @@ static struct vimoption options[] =
{(char_u *)0L, (char_u *)0L}
#endif
SCTX_INIT},
{"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
(char_u *)&p_fo, PV_FO, did_set_formatoptions, expand_set_formatoptions,
{(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
SCTX_INIT},
{"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
(char_u *)&p_flp, PV_FLP, NULL, NULL,
{(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
(char_u *)0L} SCTX_INIT},
{"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
(char_u *)&p_fo, PV_FO, did_set_formatoptions, expand_set_formatoptions,
{(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
SCTX_INIT},
{"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
(char_u *)&p_fp, PV_FP, NULL, NULL,
{(char_u *)"", (char_u *)0L} SCTX_INIT},
Expand Down Expand Up @@ -1203,6 +1203,14 @@ static struct vimoption options[] =
SCTX_INIT},


{"guiheadroom", "ghr", P_NUM|P_VI_DEF,
#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
(char_u *)&p_ghr, PV_NONE, NULL, NULL,
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
#endif
{(char_u *)50L, (char_u *)0L} SCTX_INIT},

{"guiligatures", "gli", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
#if defined(FEAT_GUI_GTK)
(char_u *)&p_guiligatures, PV_NONE,
Expand All @@ -1214,14 +1222,6 @@ static struct vimoption options[] =
#endif
SCTX_INIT},


{"guiheadroom", "ghr", P_NUM|P_VI_DEF,
#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
(char_u *)&p_ghr, PV_NONE, NULL, NULL,
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
#endif
{(char_u *)50L, (char_u *)0L} SCTX_INIT},
{"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
#if defined(FEAT_GUI)
(char_u *)&p_go, PV_NONE, did_set_guioptions, expand_set_guioptions,
Expand Down Expand Up @@ -1997,36 +1997,36 @@ static struct vimoption options[] =
{"pumwidth", "pw", P_NUM|P_VI_DEF,
(char_u *)&p_pw, PV_NONE, NULL, NULL,
{(char_u *)15L, (char_u *)15L} SCTX_INIT},
{"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
#if defined(DYNAMIC_PYTHON3)
(char_u *)&p_py3dll, PV_NONE, NULL, NULL,
{(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
{"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
#if defined(DYNAMIC_PYTHON)
(char_u *)&p_pydll, PV_NONE, NULL, NULL,
{(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
{(char_u *)NULL, (char_u *)0L}
#endif
SCTX_INIT},
{"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
#if defined(FEAT_PYTHON3)
(char_u *)&p_py3home, PV_NONE, NULL, NULL,
{"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
#if defined(FEAT_PYTHON)
(char_u *)&p_pyhome, PV_NONE, NULL, NULL,
{(char_u *)"", (char_u *)0L}
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
{(char_u *)NULL, (char_u *)0L}
#endif
SCTX_INIT},
{"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
#if defined(DYNAMIC_PYTHON)
(char_u *)&p_pydll, PV_NONE, NULL, NULL,
{(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
{"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
#if defined(DYNAMIC_PYTHON3)
(char_u *)&p_py3dll, PV_NONE, NULL, NULL,
{(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
{(char_u *)NULL, (char_u *)0L}
#endif
SCTX_INIT},
{"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
#if defined(FEAT_PYTHON)
(char_u *)&p_pyhome, PV_NONE, NULL, NULL,
{"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
#if defined(FEAT_PYTHON3)
(char_u *)&p_py3home, PV_NONE, NULL, NULL,
{(char_u *)"", (char_u *)0L}
#else
(char_u *)NULL, PV_NONE, NULL, NULL,
Expand Down Expand Up @@ -2251,20 +2251,20 @@ static struct vimoption options[] =
(char_u *)NULL, PV_NONE, NULL, NULL,
#endif
{(char_u *)0L, (char_u *)0L} SCTX_INIT},
{"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
(char_u *)&p_sxq, PV_NONE, NULL, NULL,
{"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
(char_u *)&p_sxe, PV_NONE, NULL, NULL,
{
#if defined(UNIX) && defined(USE_SYSTEM)
(char_u *)"\"",
#if defined(MSWIN)
(char_u *)"\"&|<>()@^",
#else
(char_u *)"",
#endif
(char_u *)0L} SCTX_INIT},
{"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
(char_u *)&p_sxe, PV_NONE, NULL, NULL,
{"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
(char_u *)&p_sxq, PV_NONE, NULL, NULL,
{
#if defined(MSWIN)
(char_u *)"\"&|<>()@^",
#if defined(UNIX) && defined(USE_SYSTEM)
(char_u *)"\"",
#else
(char_u *)"",
#endif
Expand Down Expand Up @@ -2850,16 +2850,16 @@ static struct vimoption options[] =
{"window", "wi", P_NUM|P_VI_DEF,
(char_u *)&p_window, PV_NONE, did_set_window, NULL,
{(char_u *)0L, (char_u *)0L} SCTX_INIT},
{"winheight", "wh", P_NUM|P_VI_DEF,
(char_u *)&p_wh, PV_NONE,
did_set_winheight_helpheight, NULL,
{(char_u *)1L, (char_u *)0L} SCTX_INIT},
{"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
(char_u *)VAR_WIN, PV_WFH, NULL, NULL,
{(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
{"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
(char_u *)VAR_WIN, PV_WFW, NULL, NULL,
{(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
{"winheight", "wh", P_NUM|P_VI_DEF,
(char_u *)&p_wh, PV_NONE,
did_set_winheight_helpheight, NULL,
{(char_u *)1L, (char_u *)0L} SCTX_INIT},
{"winminheight", "wmh", P_NUM|P_VI_DEF,
(char_u *)&p_wmh, PV_NONE, did_set_winminheight, NULL,
{(char_u *)1L, (char_u *)0L} SCTX_INIT},
Expand Down
3 changes: 3 additions & 0 deletions src/testdir/test_options.vim
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,9 @@ func Test_set_one_column()
let out_mult = execute('set all')->split("\n")
let out_one = execute('set! all')->split("\n")
call assert_true(len(out_mult) < len(out_one))
call assert_equal(out_one[0], '--- Options ---')
let options = out_one[1:]->mapnew({_, line -> line[2:]})
call assert_equal(sort(copy(options)), options)
endfunc

func Test_set_values()
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2154,
/**/
2153,
/**/
Expand Down

0 comments on commit f48558e

Please sign in to comment.