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 10/07/2011 10:38 PM, Jamison Hope wrote:
On Oct 7, 2011, at 10:33 PM, Jamison Hope wrote:

I'll tackle the primitive arrays for now and think about how to handle
cycles as a separate patch.

Here's what I came up with. I get the expected successes and failures for statements like (test-equal (byte[]) (byte[])) or (test-equal (byte[] 1 2) (long[] 1 2)).

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 ...
}


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. -- --Per Bothner per@bothner.com http://per.bothner.com/


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