InternetAddress comparison fail
Jonathan Marler via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jan 3 08:39:01 PST 2015
On Saturday, 3 January 2015 at 01:59:40 UTC, MattCoder wrote:
> On Saturday, 3 January 2015 at 01:16:39 UTC, Jonathan Marler
> wrote:
>> Why doesn't the equals operator work on the InternetAddress
>> class?
>
> It fails as the example below:
>
> import std.stdio;
>
> class foo{}
> void main(){
> auto a = new foo;
> auto b = new foo;
> assert(a == b);
> }
>
> I believe you need to compare the values inside those class
> right?
>
> Anyway, the way I'd do this is changing the line:
>
> assert(addr1 == addr2); // FAILS
>
> to
>
> assert(addr1.toAddrString() == addr2.toAddrString());
>
> Matheus.
Thanks for the suggestion. However, it brings me a little pain
to see people use the toAddrString for comparison. An
InternetAddress consists of a uint address and a ushort port.
The comparison should be 2 integer comparisons. Using
toAddrString results in the following steps:
1. Allocate memory for the InternetAddress (GC memory by the way)
2. Convert the uint address to an IP Address string
3. Convert the ushort port to a string.
4. Do steps 1-3 to the second InternetAddress
5. Do a string comparision with the two InternetAddresses.
This is so inefficient it hurts me. The steps should be:
1. Compare the uint and ushort members of InternetAddress.
done. Anyway, your suggestion works...but I hope you can
understand why it hurts me to see it...lol
More information about the Digitalmars-d
mailing list