Why does Object.opEquals *exist*

Kristian Kilpi kjkilpi at gmail.com
Sun Nov 12 09:20:45 PST 2006


On Sun, 12 Nov 2006 15:14:01 +0200, Stewart Gordon <smjg_1998 at yahoo.com>  
wrote:

> Anders F Björklund 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
>
> I'm still not convinced that there's any way that opEquals can be made  
> more efficient by returning int instead of bool.
>
> Stewart.
>

Yep. Lets consider the following simple loop, which proves the point, I  
think:

   for(i = 0; i < Y; i++)
      X;

1) If 'X' is complex, then the speed up gained by using 'int' instead of  
'bool' is meaningless. E.g. it does not matter if the loop takes 10h 2s  
instead of 10h 1s.

2) If 'X' is not complex, then the loop is finished in the blink of an  
eye. Of course, if Y is very large, then the looping takes time and using  
'int' could speed up the loop a little (lets say 5%). However, it's very  
unlikely that Y will ever be large enough. Even million is a small number  
for Y. We talking about hundred millions here. How often you have such a  
loop in your program? Maybe if you're doing graphics, but then you  
wouldn'use the object comparision in the loop. :)



More information about the Digitalmars-d mailing list