On Wednesday, 12 October 2016 at 12:46:50 UTC, Andrei Alexandrescu wrote:
On 10/12/2016 06:56 AM, Stefan Koch wrote:
I just confirmed that branching version is faster then table-lookup.


please test it our for yourself
http://paste.ofcode.org/3CpieAhkrTYEcSncbPKbrj

The table-lookup does produce the smallest code though.

Nice. I like that the table is NOT looked up on the ASCII path, so it stays cold in ASCII text. However, there's a problem with this pattern:

    size_t char_length = 1;
    immutable c = s[0];
    if (c < 192)
    {
        Lend :
        s = s.ptr[char_length .. s.length];
        return ;
    }

as opposed to:

    immutable c = s[0];
    if (c < 192)
    {
        Lend :
        s = s.ptr[1 .. s.length];
        return ;
    }

In the second case, the compiler generates an inc for bumping the pointer and a dec for decreasing the length (small instructions). If the variable char_length is used, add/sub must be used (larger). -- Andrei

btw.
We could get rid of of a sub if we changed slices from holding a pointer and a length to holding two pointers.

Reply via email to