Can you shrink it further?

Temtaime via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 11 02:45:11 PDT 2016


On Tuesday, 11 October 2016 at 09:13:10 UTC, Stefan Koch wrote:
> On Tuesday, 11 October 2016 at 08:57:46 UTC, Stefan Koch wrote:
>> On Tuesday, 11 October 2016 at 08:44:04 UTC, Temtaime wrote:
>>>
>>> void popFront1(ref char[] s) @trusted pure nothrow
>>> {
>>>   import core.bitop, std.algorithm;
>>>   auto v = bsr(~s[0] | 1);
>>>   s = s[clamp(v, 1, v > 6 ? 1 : $)..$];
>>> }
>>>
>>> Seems to be less if i'm not wrong.
>>
>>
>> Yours runs with 790 us best time.
>> bsr is a real timetaker :)
>
> CORRECTION this is not bsr's fault.
> It's most likely clamp.
> I am compiling with dmd and dmd is not as good in optimizing 
> when templates are in the mix.

Sorry this was also a type in the code.

void popFront7(ref char[] s) @trusted pure nothrow
{
   import core.bitop;
   auto v = 7 - bsr(~s[0] | 1);
   s = s[v > 6 ? 1 : (v ? (v > s.length ? s.length : v) : 1)..$];
}

Please check this.


More information about the Digitalmars-d mailing list