@@ -495,40 +495,81 @@ static void ex_folddo(exarg_T *eap);
495495#define DO_DECLARE_EXCMD
496496#include "ex_cmds.h"
497497
498+ /* Beginning of automatically generated code by create_cmdidxs.pl
499+ *
500+ * Table giving the index of the first command in cmdnames[] to lookup
501+ * based on the first letter of a command.
502+ */
503+ static const unsigned short cmdidxs1 [26 ] =
504+ {
505+ /* a */ 0 ,
506+ /* b */ 19 ,
507+ /* c */ 42 ,
508+ /* d */ 103 ,
509+ /* e */ 125 ,
510+ /* f */ 145 ,
511+ /* g */ 161 ,
512+ /* h */ 167 ,
513+ /* i */ 176 ,
514+ /* j */ 194 ,
515+ /* k */ 196 ,
516+ /* l */ 201 ,
517+ /* m */ 259 ,
518+ /* n */ 277 ,
519+ /* o */ 297 ,
520+ /* p */ 309 ,
521+ /* q */ 348 ,
522+ /* r */ 351 ,
523+ /* s */ 370 ,
524+ /* t */ 437 ,
525+ /* u */ 472 ,
526+ /* v */ 483 ,
527+ /* w */ 501 ,
528+ /* x */ 516 ,
529+ /* y */ 525 ,
530+ /* z */ 526
531+ };
532+
498533/*
499- * Table used to quickly search for a command, based on its first character.
500- */
501- static cmdidx_T cmdidxs [27 ] =
502- {
503- CMD_append ,
504- CMD_buffer ,
505- CMD_change ,
506- CMD_delete ,
507- CMD_edit ,
508- CMD_file ,
509- CMD_global ,
510- CMD_help ,
511- CMD_insert ,
512- CMD_join ,
513- CMD_k ,
514- CMD_list ,
515- CMD_move ,
516- CMD_next ,
517- CMD_open ,
518- CMD_print ,
519- CMD_quit ,
520- CMD_read ,
521- CMD_substitute ,
522- CMD_t ,
523- CMD_undo ,
524- CMD_vglobal ,
525- CMD_write ,
526- CMD_xit ,
527- CMD_yank ,
528- CMD_z ,
529- CMD_bang
534+ * Table giving the index of the first command in cmdnames[] to lookup
535+ * based on the first 2 letters of a command.
536+ * Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they
537+ * fit in a byte.
538+ */
539+ static const unsigned char cmdidxs2 [26 ][26 ] =
540+ { /* a b c d e f g h i j k l m n o p q r s t u v w x y z */
541+ /* a */ { 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 4 , 5 , 6 , 0 , 0 , 0 , 7 , 15 , 0 , 16 , 0 , 0 , 0 , 0 , 0 , },
542+ /* b */ { 0 , 0 , 0 , 4 , 5 , 7 , 0 , 0 , 0 , 0 , 0 , 8 , 9 , 10 , 11 , 12 , 0 , 13 , 0 , 0 , 0 , 0 , 22 , 0 , 0 , 0 , },
543+ /* c */ { 0 , 10 , 12 , 14 , 16 , 18 , 21 , 0 , 0 , 0 , 0 , 29 , 33 , 36 , 42 , 51 , 53 , 54 , 55 , 0 , 57 , 0 , 60 , 0 , 0 , 0 , },
544+ /* d */ { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 15 , 0 , 16 , 0 , 0 , 17 , 0 , 0 , 19 , 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , },
545+ /* e */ { 0 , 0 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 9 , 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 16 , 0 , 0 , },
546+ /* f */ { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 9 , 0 , 0 , 0 , 0 , 0 , 15 , 0 , 0 , 0 , 0 , 0 , },
547+ /* g */ { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 2 , 0 , 0 , 4 , 5 , 0 , 0 , 0 , 0 , },
548+ /* h */ { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , },
549+ /* i */ { 0 , 0 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , 4 , 0 , 5 , 6 , 0 , 0 , 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 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 13 , 18 , 0 , 0 , 0 , 0 , },
559+ /* s */ { 0 , 6 , 15 , 0 , 18 , 22 , 0 , 24 , 25 , 0 , 0 , 28 , 30 , 34 , 38 , 40 , 0 , 48 , 0 , 49 , 0 , 61 , 62 , 0 , 63 , 0 , },
560+ /* t */ { 0 , 0 , 19 , 0 , 22 , 23 , 0 , 24 , 0 , 25 , 0 , 26 , 27 , 28 , 29 , 30 , 0 , 31 , 33 , 0 , 34 , 0 , 0 , 0 , 0 , 0 , },
561+ /* u */ { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , },
562+ /* v */ { 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 4 , 0 , 0 , 0 , 9 , 12 , 0 , 0 , 0 , 0 , 15 , 0 , 16 , 0 , 0 , 0 , 0 , 0 , },
563+ /* w */ { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 , 4 , 0 , 0 , 0 , 0 , 8 , 0 , 9 , 10 , 0 , 12 , 0 , 13 , 14 , 0 , 0 , 0 , 0 , },
564+ /* x */ { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 0 , 0 , 0 , 0 , 0 , },
565+ /* y */ { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , },
566+ /* z */ { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , }
530567};
531568
569+ static int command_count = 539 ;
570+
571+ /* End of automatically generated code by create_cmdidxs.pl */
572+
532573static char_u dollar_command [2 ] = {'$' , 0 };
533574
534575
@@ -614,7 +655,6 @@ restore_dbg_stuff(struct dbg_stuff *dsp)
614655}
615656#endif
616657
617-
618658/*
619659 * do_exmode(): Repeatedly get commands for the "Ex" mode, until the ":vi"
620660 * command is given.
@@ -3208,10 +3248,24 @@ find_command(exarg_T *eap, int *full UNUSED)
32083248 }
32093249 }
32103250
3211- if (ASCII_ISLOWER (* eap -> cmd ))
3212- eap -> cmdidx = cmdidxs [CharOrdLow (* eap -> cmd )];
3251+ if (ASCII_ISLOWER (eap -> cmd [0 ]))
3252+ {
3253+ if (command_count != (int )CMD_SIZE )
3254+ {
3255+ iemsg ((char_u * )_ ("E943: Command table needs to be updated, run 'make cmdidxs'" ));
3256+ getout (1 );
3257+ }
3258+
3259+ /* Use a precomputed index for fast look-up in cmdnames[]
3260+ * taking into account the first 2 letters of eap->cmd. */
3261+ int c1 = eap -> cmd [0 ];
3262+ int c2 = eap -> cmd [1 ];
3263+ eap -> cmdidx = cmdidxs1 [CharOrdLow (c1 )];
3264+ if (ASCII_ISLOWER (c2 ))
3265+ eap -> cmdidx += cmdidxs2 [CharOrdLow (c1 )][CharOrdLow (c2 )];
3266+ }
32133267 else
3214- eap -> cmdidx = cmdidxs [ 26 ] ;
3268+ eap -> cmdidx = CMD_bang ;
32153269
32163270 for ( ; (int )eap -> cmdidx < (int )CMD_SIZE ;
32173271 eap -> cmdidx = (cmdidx_T )((int )eap -> cmdidx + 1 ))
0 commit comments