int opEquals(Object), and other legacy ints
xs0
xs0 at xs0.com
Fri Jul 28 04:05:30 PDT 2006
>> It's a byte internally, and is constrained to be one of the values 0
>> or 1.
>
> Duh, it's a byte of course, I should have checked that.
>
> But the question remains, is it then less efficient to return a byte
> than a int? Why? And if so isn't there a way for the compiler to somehow
> optimize it?
> 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. :/
Well, I'm just guessing, but I think something like
> int opEquals(Foo foo)
> {
> return this.bar == foo.bar;
> }
is compiled to something like
> return this.bar-foo.bar; // 1 instruction
but if the return type is bool, it becomes
> return this.bar-foo.bar?1:0; // 3 instructions
It's the 1/0 constraint on bools that causes the slowness, not the size
(stack is usually size_t-aligned anyway)
xs0
More information about the Digitalmars-d-bugs
mailing list