Can you shrink it further?

Stefan Koch via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 10 08:17:05 PDT 2016


On Monday, 10 October 2016 at 03:55:17 UTC, Andrei Alexandrescu 
wrote:
>
> Oh, forgot to mention: the initial/short path should only check 
> for ASCII, i.e. c < 0x80. -- Andrei

void popFront1(ref char[] s) @trusted pure nothrow {
   immutable c = s[0];
   size_t char_length = 1;
   if (!(c & 0x80)) {
     goto Lend;
   } else {
     import core.bitop;
     uint i = 7u - bsr(~c | 1u);
     import std.algorithm;
     if (i > 6u) goto Lend;
     char_length = min(i, s.length);
   }
   Lend :
   s = s.ptr[char_length .. s.length];
}


This one removes one unnecessary ret.
It will also probably be better for the branch-predictor.


More information about the Digitalmars-d mailing list