Yegappan wrote:

> On Wed, Jan 19, 2022 at 4:34 AM Bram Moolenaar ***@***.***>
> wrote:
> 
> > I'm not sure this is an improvement. Using a switch statement the compiler
> > can find the optimal way to select the code to execute. A linear search
> > through an array is likely to always be slower.
> > A binary search would be much better, but it is hard to get the key codes
> > in sorted order.
> > A kind of hashtable might also work. It would have to be created at
> > runtime though.
> >
> > We have a similar problem for the normal mode command, which is using a
> > sorted index table. It is filled in init_normal_cmds().
> > This adds to the startup time.
> >
> > We could change this to generate the table at compile time. Then the table
> > used for "g" commands could also use a binary search, like in
> > find_command(). The "g" command table would have gaps in the lower block
> > (the part where the typed character can directly be used as an index, up to
> > "~"). Or not use a lower block.
> >
> >
> >
> I will rework the patch to use a binary search to lookup the function for a
> given key.

We have "make cmdidxs" for the table of Ex commands.  It's a different
mechanism, but the way it is used can function as an example.  The
result is efficient at runtime.

Perhaps we just need a script that can sort the array, so that a binary
search is possible.  Or generate the lookup table, so that
init_normal_cmds() isn't needed.

-- 
LAUNCELOT: I am, sir. I am a Knight of King Arthur.
FATHER:    'Mm ... very nice castle, Camelot ... very good pig country....
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220119165849.A37401C0243%40moolenaar.net.

Raspunde prin e-mail lui