int opEquals(Object), and other legacy ints
    Walter Bright 
    newshound at digitalmars.com
       
    Fri Jul 28 17:19:50 PDT 2006
    
    
  
Bruno Medeiros wrote:
> But the question remains, is it then less efficient to return a byte 
> than a int?
Yes. It's also less efficient to constrain the results to 0 or 1.
> Why?
Consider:
	a = 0x1000;
	b = 0x2000;
Now convert (a == b) into a bool. If the result is an int, I can just do 
(a - b), one instruction. Converting it to a byte, or to 1 or 0, takes more.
> And if so isn't there a way for the compiler to somehow 
> optimize it?
The math is inevitable <g>.
> I find it a bit hard to believe that nowadays there isn't sufficient 
> compiler and/or CPU technology to somehow make a bool(byte) return value 
> as efficient as a int one. :/
I work with what the CPU makes available.
P.S. Inevitably, some will ask "who cares" about these small 
efficiencies. The trouble is, these kinds of things often appear in 
tight loops, where small inefficiencies get multiplied by millions.
    
    
More information about the Digitalmars-d-bugs
mailing list