changeset 33897:7777043c9393 v9.0.2154

patch 9.0.2154: The option[] array is not sorted Commit: https://github.com/vim/vim/commit/f48558e10a08a1a483e25ef847bbceeac6b44561 Author: zeertzjq <zeertzjq@outlook.com> Date: Fri Dec 8 21:34:31 2023 +0100 patch 9.0.2154: The option[] array is not sorted 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>
author Christian Brabandt <cb@256bit.org>
date Sun, 10 Dec 2023 15:16:32 +0100
parents c62bca3b8d82
children c30e06a0a180
files src/option.c src/optiondefs.h src/testdir/test_options.vim src/version.c
diffstat 4 files changed, 91 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/src/option.c
+++ b/src/option.c
@@ -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])];
--- a/src/optiondefs.h
+++ b/src/optiondefs.h
@@ -341,6 +341,20 @@ static struct vimoption options[] =
 			    (char_u *)NULL, PV_NONE, NULL, NULL,
 			    {(char_u *)FALSE, (char_u *)FALSE}
 			    SCTX_INIT},
+    {"allowrevins", "ari",  P_BOOL|P_VI_DEF|P_VIM,
+#ifdef FEAT_RIGHTLEFT
+			    (char_u *)&p_ari, PV_NONE, NULL, NULL,
+#else
+			    (char_u *)NULL, PV_NONE, NULL, NULL,
+#endif
+			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
+    {"altkeymap",   "akm",  P_BOOL|P_VI_DEF,
+			    (char_u *)NULL, PV_NONE, NULL, NULL,
+			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
+    {"ambiwidth",  "ambw",  P_STRING|P_VI_DEF|P_RCLR,
+			    (char_u *)&p_ambw, PV_NONE, did_set_ambiwidth, expand_set_ambiwidth,
+			    {(char_u *)"single", (char_u *)0L}
+			    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,
@@ -355,20 +369,6 @@ static struct vimoption options[] =
 			    (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,
-#else
-			    (char_u *)NULL, PV_NONE, NULL, NULL,
-#endif
-			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
-    {"altkeymap",   "akm",  P_BOOL|P_VI_DEF,
-			    (char_u *)NULL, PV_NONE, NULL, NULL,
-			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
-    {"ambiwidth",  "ambw",  P_STRING|P_VI_DEF|P_RCLR,
-			    (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,
@@ -378,15 +378,6 @@ static struct vimoption options[] =
 			    {(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}
-#else
-			    (char_u *)NULL, PV_NONE, NULL, NULL,
-			    {(char_u *)0L, (char_u *)0L}
-#endif
-			    SCTX_INIT},
     {"autoindent",  "ai",   P_BOOL|P_VI_DEF,
 			    (char_u *)&p_ai, PV_AI, NULL, NULL,
 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
@@ -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},
@@ -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,
@@ -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,
@@ -1091,14 +1091,14 @@ static struct vimoption options[] =
 			    {(char_u *)0L, (char_u *)0L}
 #endif
 			    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},
-    {"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},
     {"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},
@@ -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,
@@ -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,
@@ -1997,6 +1997,24 @@ 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},
+    {"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},
+    {"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},
     {"pythonthreedll",  NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
 #if defined(DYNAMIC_PYTHON3)
 			    (char_u *)&p_py3dll, PV_NONE, NULL, NULL,
@@ -2015,24 +2033,6 @@ static struct vimoption options[] =
 			    {(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}
-#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,
-			    {(char_u *)"", (char_u *)0L}
-#else
-			    (char_u *)NULL, PV_NONE, NULL, NULL,
-			    {(char_u *)NULL, (char_u *)0L}
-#endif
-			    SCTX_INIT},
     {"pyxversion", "pyx",   P_NUM|P_VI_DEF|P_SECURE,
 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
 			    (char_u *)&p_pyx, PV_NONE, did_set_pyxversion, NULL,
@@ -2251,6 +2251,15 @@ static struct vimoption options[] =
 			    (char_u *)NULL, PV_NONE, NULL, NULL,
 #endif
 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
+    {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
+			    (char_u *)&p_sxe, PV_NONE, NULL, NULL,
+			    {
+#if defined(MSWIN)
+			    (char_u *)"\"&|<>()@^",
+#else
+			    (char_u *)"",
+#endif
+				(char_u *)0L} SCTX_INIT},
     {"shellxquote", "sxq",  P_STRING|P_VI_DEF|P_SECURE,
 			    (char_u *)&p_sxq, PV_NONE, NULL, NULL,
 			    {
@@ -2260,15 +2269,6 @@ static struct vimoption options[] =
 			    (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,
-			    {
-#if defined(MSWIN)
-			    (char_u *)"\"&|<>()@^",
-#else
-			    (char_u *)"",
-#endif
-				(char_u *)0L} SCTX_INIT},
     {"shiftround",  "sr",   P_BOOL|P_VI_DEF|P_VIM,
 			    (char_u *)&p_sr, PV_NONE, NULL, NULL,
 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
@@ -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},
--- a/src/testdir/test_options.vim
+++ b/src/testdir/test_options.vim
@@ -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()
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2154,
+/**/
     2153,
 /**/
     2152,