diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-03-10 17:27:29 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-03-27 23:43:16 -0400 |
commit | c3158e230deec5039f33477aa4aa78f5f8ad25af (patch) | |
tree | c88406dd71dde1cce757649e12c04b97e5318647 | |
parent | 2470c88291ef1e4db6b49fd1adf17bc7fb6ecd39 (diff) | |
download | rneovim-c3158e230deec5039f33477aa4aa78f5f8ad25af.tar.gz rneovim-c3158e230deec5039f33477aa4aa78f5f8ad25af.tar.bz2 rneovim-c3158e230deec5039f33477aa4aa78f5f8ad25af.zip |
vim-patch:8.0.0504: looking up an Ex command is a bit slow
Problem: Looking up an Ex command is a bit slow.
Solution: Instead of just using the first letter, also use the second letter
to skip ahead in the list of commands. Generate the table with a
Perl script. (Dominique Pelle, closes vim/vim#1589)
https://github.com/vim/vim/commit/e5e0fbcd4244d032a0635ad7defe2831f251c639
-rw-r--r-- | src/nvim/ex_docmd.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index fbe41f9914..1bd3b004f0 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -155,6 +155,8 @@ struct dbg_stuff { # include "ex_cmds_defs.generated.h" #endif +static const int command_count = 539; + static char_u dollar_command[2] = {'$', 0}; static void save_dbg_stuff(struct dbg_stuff *dsp) @@ -2440,10 +2442,23 @@ static char_u *find_command(exarg_T *eap, int *full) } } - if (ASCII_ISLOWER(*eap->cmd)) - eap->cmdidx = cmdidxs[CharOrdLow(*eap->cmd)]; - else - eap->cmdidx = cmdidxs[26]; + if (ASCII_ISLOWER(eap->cmd[0])) { + if (command_count != (int)CMD_SIZE) { + iemsg((char_u *)_("E943: Command table needs to be updated, run 'make cmdidxs'")); + getout(1); + } + + // Use a precomputed index for fast look-up in cmdnames[] + // taking into account the first 2 letters of eap->cmd. + const int c1 = eap->cmd[0]; + const int c2 = eap->cmd[1]; + eap->cmdidx = cmdidxs1[CharOrdLow(c1)]; + if (ASCII_ISLOWER(c2)) { + eap->cmdidx += cmdidxs2[CharOrdLow(c1)][CharOrdLow(c2)]; + } + } else { + eap->cmdidx = CMD_bang; + } for (; (int)eap->cmdidx < (int)CMD_SIZE; eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1)) |