Why does Object.opEquals *exist*

Stewart Gordon smjg_1998 at yahoo.com
Sun Nov 12 13:07:49 PST 2006


Kristian Kilpi wrote:
> On Sun, 12 Nov 2006 15:14:01 +0200, Stewart Gordon <smjg_1998 at yahoo.com> 
> wrote:
<snip>
>> I'm still not convinced that there's any way that opEquals can be made 
>> more efficient by returning int instead of bool.
<snip>
> 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. :)

That's an illustration of how a general expression of type int can be 
more efficient than the same expression converted to a bool.  But it 
tells me nothing about how _opEquals_ can be more efficient if it's of 
type int.

My point is this.  An opEquals of type int will necessarily return 0 for 
non-equal or non-0 for equal.  But what can this non-0 be that can 
possibly be more efficient than simply returning 1 if they're equal, and 
thereby removing the need for the overhead of converting it to bool?

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- 
PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.



More information about the Digitalmars-d mailing list