Can you shrink it further?

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 12 05:46:50 PDT 2016


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


More information about the Digitalmars-d mailing list