[m-rev.] For review: Java implementation of array library

James Goddard goddardjames at yahoo.com
Fri Jan 9 13:18:45 AEDT 2004


This is a better fix:

diff -u array.m array.m
--- array.m	8 Jan 2004 06:14:42 -0000
+++ array.m	9 Jan 2004 02:17:45 -0000
@@ -987,25 +987,21 @@
 "
 	java.lang.Class itemClass = Item.getClass();
 
-	if (Array0 == null) {
+	if (Size == 0) {
+		Array = null;
+	} else if (Array0 == null) {
 		Array = java.lang.reflect.Array.newInstance(itemClass, Size);
 		for (int i = 0; i < Size; i++) {
 			java.lang.reflect.Array.set(Array, i, Item);
 		}
 	} else if (java.lang.reflect.Array.getLength(Array0) == Size) {
 		Array = Array0;
-	} else if (java.lang.reflect.Array.getLength(Array0) > Size) {
-		Array = java.lang.reflect.Array.newInstance(itemClass, Size);
-		for (int i = 0; i < Size; i++) {
-			java.lang.reflect.Array.set(Array, i,
-					java.lang.reflect.Array.get(Array0, i)
-					);
-		}
 	} else {
 		Array = java.lang.reflect.Array.newInstance(itemClass, Size);
 
 		int i;
-		for (i = 0; i < java.lang.reflect.Array.getLength(Array0); i++)
+		for (i = 0; i < java.lang.reflect.Array.getLength(Array0) &&
+				i < Size; i++)
 		{
 			java.lang.reflect.Array.set(Array, i,
 					java.lang.reflect.Array.get(Array0, i)
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list