Optimization in std.algorithm.max?
Jesse Phillips
Jesse.K.Phillips at gmail.com
Tue Nov 22 12:28:06 PST 2011
There is a good possibility that I don't know anything, but is there something about doing two checks that goes faster?
static if (isIntegral!(T1) && isIntegral!(T2)
&& (mostNegative!(T1) < 0) != (mostNegative!(T2) < 0))
static if (mostNegative!(T1) < 0)
immutable chooseB = b > a || a < 0;
else
immutable chooseB = b > a && b > 0;
else
immutable chooseB = b > a;
What has me baffled is the second checks after b > a. Doesn't b > a always answer the question? The only thing I can think of is a check for negative being faster, so shouldn't they come before the b > a check?
More information about the Digitalmars-d-learn
mailing list