From c3158e230deec5039f33477aa4aa78f5f8ad25af Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 10 Mar 2019 17:27:29 -0400 Subject: 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 --- src/nvim/ex_docmd.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/nvim/ex_docmd.c') 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)) -- cgit From 07a5c9d4f0b8e72349bb4406f39b8fd2daa74af7 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 10 Mar 2019 17:38:33 -0400 Subject: vim-patch:8.0.0506: can't build with ANSI C Problem: Can't build with ANSI C. Solution: Move declarations to start of block. https://github.com/vim/vim/commit/6c0c1e8052811a818739e2f3d543291b7a347ad0 --- src/nvim/ex_docmd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_docmd.c') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 1bd3b004f0..e91b6b6470 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2443,6 +2443,9 @@ static char_u *find_command(exarg_T *eap, int *full) } if (ASCII_ISLOWER(eap->cmd[0])) { + const int c1 = eap->cmd[0]; + const int c2 = eap->cmd[1]; + if (command_count != (int)CMD_SIZE) { iemsg((char_u *)_("E943: Command table needs to be updated, run 'make cmdidxs'")); getout(1); @@ -2450,8 +2453,6 @@ static char_u *find_command(exarg_T *eap, int *full) // 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)]; -- cgit From 63025a1d65bf7dbfcf4f3d543c1da9b0d34ebd56 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 10 Mar 2019 17:41:18 -0400 Subject: gen_ex_cmds.lua: build the command table Lua port of create_cmdidxs.vim from 8.0.0572 N/A: vim-patch:8.0.0572: building the command table requires Perl Problem: Building the command table requires Perl. Solution: Use a Vim script solution. (Dominique Pelle, closes vim/vim#1641) https://github.com/vim/vim/commit/6de5e126018b6f92526795cc06b1d73fac965db1 --- src/nvim/ex_docmd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/nvim/ex_docmd.c') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index e91b6b6470..037b5dec7f 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -155,8 +155,6 @@ 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) @@ -2265,8 +2263,11 @@ static char_u * do_one_cmd(char_u **cmdlinep, need_rethrow = check_cstack = FALSE; doend: - if (curwin->w_cursor.lnum == 0) /* can happen with zero line number */ + // can happen with zero line number + if (curwin->w_cursor.lnum == 0) { curwin->w_cursor.lnum = 1; + curwin->w_cursor.col = 0; + } if (errormsg != NULL && *errormsg != NUL && !did_emsg) { if (flags & DOCMD_VERBOSE) { @@ -2447,7 +2448,7 @@ static char_u *find_command(exarg_T *eap, int *full) const int c2 = eap->cmd[1]; if (command_count != (int)CMD_SIZE) { - iemsg((char_u *)_("E943: Command table needs to be updated, run 'make cmdidxs'")); + iemsg((char *)_("E943: Command table needs to be updated, run 'make'")); getout(1); } -- cgit