Why does Object.opEquals *exist*
Kristian Kilpi
kjkilpi at gmail.com
Thu Nov 9 09:36:58 PST 2006
On Thu, 09 Nov 2006 13:57:00 +0200, Anders F Björklund <afb at algonet.se>
wrote:
> Kristian Kilpi wrote:
>
>> So the original question remains: why 'opEquals' returns int?
>
> Walter says it is for performance reason, when e.g. sorting...
>
> http://www.digitalmars.com/d/archives/digitalmars/D/bugs/7933.html
>
> --anders
Well, I don't like it ;) , even though more speed is good. 'opEquals' have
to be used in pretty simple algorithms to gain speed advantage over bool.
I mean, for example, a loop consist of 100 instructions, and we're talking
here saving 1 - 3 instructions per one loop. If looping takes 1 min, we
save 1.8 secs at maximum... And I think loops etc nowadays contain more
likely thousands of instructions instead of hundreds. Of course, very low
level stuff is good to be as fast as possible, but if you need to save
these 1 - 3 instructions, then you should use assembly anyway; I'm pretty
sure that no compiler produces optimal assembly code. ;)
So, maybe the actual reason of this is that chaging the return type would
break old code?
I'm just afraid what public will think of this.
More information about the Digitalmars-d
mailing list