Dominique wrote:
> > Patch 8.2.2654
> > Problem: Vim9: getting a character from a string can be slow.
> > Solution: Avoid a function call to get the character byte size. (#8000)
> > Files: src/vim9execute.vim
> ...snip...
> > for (nbyte = 0; nbyte < slen; ++clen)
> > ! {
> > ! if (str[nbyte] < 0x80 && str[nbyte + 1] < 0x80)
> > ! ++nbyte;
> > ! else if (enc_utf8)
> > ! nbyte += utfc_ptr2len(str + nbyte);
> > ! else
> > ! nbyte += mb_ptr2len(str + nbyte);
> > ! }
>
> Is this correct? I would have thought that the following line is
> correct for utf8 encoding but not for all other encodings:
>
> if (str[nbyte] < 0x80 && str[nbyte + 1] < 0x80)
>
> So I think that loop should rather be something like this:
>
> if (enc_utf8)
> for (nbyte = 0; nbyte < slen; ++clen)
> {
> if (str[nbyte] < 0x80 && str[nbyte + 1] < 0x80)
> ++nbyte;
> else
> nbyte += utfc_ptr2len(str + nbyte);
> }
> else
> for (nbyte = 0; nbyte < slen; ++clen)
> nbyte += mb_ptr2len(str + nbyte);
You can compare with some benchmark what the difference is. I would
think that enc_utf8 is cached and the choice between utfc_ptr2len() and
mb_ptr2len() doesn't make a measurable difference. Not worth for
duplicating the loop.
AFAIK there is no encoding where a character with a first byte below
0x80 takes more than one byte.
--
How To Keep A Healthy Level Of Insanity:
13. Go to a poetry recital and ask why the poems don't rhyme.
/// 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/202103261443.12QEhprQ334953%40masaka.moolenaar.net.