This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: equal? and primitive arrays


On Oct 8, 2011, at 2:19 AM, Per Bothner wrote:

In arrayEquals we could perhaps simplify/optimize slightly:

String tname1 = arg1.getClass().getName();
String tname2 = arg2.getClass().getName();
// int[].class.getName() returns "[I" etc
if (tname1.length() == 2 && tname2.equals(tname1)) { // matching primitive types
switch (tname1.charAt(1)) {
case 'Z': return Arrays.equals((boolean[]) arg1, (boolean[]) arg2);
... etc ...
}

Attached.


I'm a little uncertain what the correct behavior should be for edge
cases like comparing a String[] to an FString[] in which each pair
of elements are equal?. For now, that will return #f because the
array component types are not equal (in the Java sense).

I think the result should be #f because the types are different.

OK, that was my suspicion. It makes the implementation a little simpler, too, because I can shortcut the test with

if (!tname1.equals(tname2)) return false;

and avoid having to further examine the two array element types to see if
they are "compatible" in some complicated way. (And if I deferred to the
element-wise equality checks, then any two zero-length arrays might end up
being equal regardless of their respective types.)


--
Jamison Hope
The PTR Group
www.theptrgroup.com


Attachment: IsEqual.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]