> > One more thing to keep in mind: Creating a Dict and putting items in it
> > has quite a bit of overhead.  The two levels of Dicts means the function
> > is not going to be efficient.  For short lists this might not matter
> > much, but what if it is used on a long list?  Perhaps using one Dict per
> > hunk would be OK without making it less usable.  Might even make it
> > simpler to understand.
> >
> 
> I have updated the PR to reduce one level in the Dict.  I cannot make it a
> single flat Dict as we need to separate out the "from" and "to"
> position information.

Hmm, this still uses a Dict of Dicts.

It could be flattened by using a "from-" and "to-" prefix instead of
using separate Dicts.  Is that getting too ugly?

There are several alternatives to represent the same information.  E.g.,
instead of using a "start index" and "end index" it could be "index" and
"item count".  You would then have:
        from_index
        from_count
        to_index
        to_count

That looks OK to me.  Does this also work for the byte values?  How
about:
        from_byte
        from_length
        to_byte
        to_length

It's probably a matter of taste what to call these, but at least taking
out a level of Dict nesting will make it simpler and more efficient.
Perhaps trying this out with the examples you can see if this also works
for corner cases.

-- 
I used to be indecisive, now I'm not sure.

 /// 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/20230505173816.1A0561C1B21%40moolenaar.net.

Raspunde prin e-mail lui