Bram Moolenaar 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);

Regards
Dominique

-- 
-- 
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/CAON-T_guhg95fr%3DiksF11ZXJ8XwqK%3DjqVnjE%2Bh_xB4S7MgbKsQ%40mail.gmail.com.

Raspunde prin e-mail lui