@@ -502,40 +502,81 @@ static void ex_folddo(exarg_T *eap);
502502#define DO_DECLARE_EXCMD
503503#include "ex_cmds.h"
504504
505+ /* Beginning of automatically generated code by create_cmdidxs.pl
506+ *
507+ * Table giving the index of the first command in cmdnames[] to lookup
508+ * based on the first letter of a command.
509+ */
510+ static const unsigned short cmdidxs1 [26 ] =
511+ {
512+ /* a */ 0 ,
513+ /* b */ 19 ,
514+ /* c */ 42 ,
515+ /* d */ 103 ,
516+ /* e */ 125 ,
517+ /* f */ 145 ,
518+ /* g */ 161 ,
519+ /* h */ 167 ,
520+ /* i */ 176 ,
521+ /* j */ 194 ,
522+ /* k */ 196 ,
523+ /* l */ 201 ,
524+ /* m */ 259 ,
525+ /* n */ 277 ,
526+ /* o */ 297 ,
527+ /* p */ 309 ,
528+ /* q */ 348 ,
529+ /* r */ 351 ,
530+ /* s */ 370 ,
531+ /* t */ 437 ,
532+ /* u */ 472 ,
533+ /* v */ 483 ,
534+ /* w */ 501 ,
535+ /* x */ 516 ,
536+ /* y */ 525 ,
537+ /* z */ 526
538+ };
539+
505540/*
506- * Table used to quickly search for a command, based on its first character.
507- */
508- static cmdidx_T cmdidxs [27 ] =
509- {
510- CMD_append ,
511- CMD_buffer ,
512- CMD_change ,
513- CMD_delete ,
514- CMD_edit ,
515- CMD_file ,
516- CMD_global ,
517- CMD_help ,
518- CMD_insert ,
519- CMD_join ,
520- CMD_k ,
521- CMD_list ,
522- CMD_move ,
523- CMD_next ,
524- CMD_open ,
525- CMD_print ,
526- CMD_quit ,
527- CMD_read ,
528- CMD_substitute ,
529- CMD_t ,
530- CMD_undo ,
531- CMD_vglobal ,
532- CMD_write ,
533- CMD_xit ,
534- CMD_yank ,
535- CMD_z ,
536- CMD_bang
541+ * Table giving the index of the first command in cmdnames[] to lookup
542+ * based on the first 2 letters of a command.
543+ * Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they
544+ * fit in a byte.
545+ */
546+ static const unsigned char cmdidxs2 [26 ][26 ] =
547+ { /* 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 */
548+ /* 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 , },
549+ /* 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 , },
550+ /* 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 , },
551+ /* 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 , },
552+ /* 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 , },
553+ /* 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 , },
554+ /* 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 , },
555+ /* 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 , },
556+ /* 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 , },
566+ /* 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 , },
567+ /* 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 , },
568+ /* 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 , },
569+ /* 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 , },
570+ /* 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 , },
571+ /* 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 , },
572+ /* 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 , },
573+ /* 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 , }
537574};
538575
576+ static int command_count = 539 ;
577+
578+ /* End of automatically generated code by create_cmdidxs.pl */
579+
539580static char_u dollar_command [2 ] = {'$' , 0 };
540581
541582
@@ -621,7 +662,6 @@ restore_dbg_stuff(struct dbg_stuff *dsp)
621662}
622663#endif
623664
624-
625665/*
626666 * do_exmode(): Repeatedly get commands for the "Ex" mode, until the ":vi"
627667 * command is given.
@@ -3215,10 +3255,25 @@ find_command(exarg_T *eap, int *full UNUSED)
32153255 }
32163256 }
32173257
3218- if (ASCII_ISLOWER (* eap -> cmd ))
3219- eap -> cmdidx = cmdidxs [CharOrdLow (* eap -> cmd )];
3258+ if (ASCII_ISLOWER (eap -> cmd [0 ]))
3259+ {
3260+ int c1 = eap -> cmd [0 ];
3261+ int c2 = eap -> cmd [1 ];
3262+
3263+ if (command_count != (int )CMD_SIZE )
3264+ {
3265+ iemsg ((char_u * )_ ("E943: Command table needs to be updated, run 'make cmdidxs'" ));
3266+ getout (1 );
3267+ }
3268+
3269+ /* Use a precomputed index for fast look-up in cmdnames[]
3270+ * taking into account the first 2 letters of eap->cmd. */
3271+ eap -> cmdidx = cmdidxs1 [CharOrdLow (c1 )];
3272+ if (ASCII_ISLOWER (c2 ))
3273+ eap -> cmdidx += cmdidxs2 [CharOrdLow (c1 )][CharOrdLow (c2 )];
3274+ }
32203275 else
3221- eap -> cmdidx = cmdidxs [ 26 ] ;
3276+ eap -> cmdidx = CMD_bang ;
32223277
32233278 for ( ; (int )eap -> cmdidx < (int )CMD_SIZE ;
32243279 eap -> cmdidx = (cmdidx_T )((int )eap -> cmdidx + 1 ))
0 commit comments