This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

Patch: Remove exception catching from normal path in Arrays.equals.


Greetings:

Currently all variants of java.util.Arrays.equals() catch NullPointerExceptions to detect null valued parameters. In one of our programs this is a fairly common case and the throw/catch overhead was significant.

This patch replaces the exception catching logic with explicit checks for null values.


2003-09-05  David Daney <ddaney@avtrex.com>
	
	* java/util/Arrays.java (equals(all variants)): Quit using
	NullPointerException catching to detect null valued parameters.



Index: Arrays.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/util/Arrays.java,v
retrieving revision 1.8
diff -u -3 -b -r1.8 Arrays.java
--- Arrays.java	16 Jun 2002 21:15:41 -0000	1.8
+++ Arrays.java	5 Sep 2003 18:39:05 -0000
@@ -398,8 +398,9 @@
     if (a1 == a2)
       return true;
 
-    try
-      {
+    if (null == a1 || null == a2)
+        return false;
+    
         // If they're the same length, test each element
         if (a1.length == a2.length)
           {
@@ -409,12 +410,6 @@
                 return false;
             return true;
           }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
-      }
-
     return false;
   }
 
@@ -433,8 +428,9 @@
     if (a1 == a2)
       return true;
 
-    try
-      {
+    if (null == a1 || null == a2)
+        return false;
+
         // If they're the same length, test each element
         if (a1.length == a2.length)
           {
@@ -444,11 +440,6 @@
                 return false;
             return true;
           }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
-      }
     return false;
   }
 
@@ -467,8 +458,9 @@
     if (a1 == a2)
       return true;
 
-    try
-      {
+    if (null == a1 || null == a2)
+        return false;
+    
         // If they're the same length, test each element
         if (a1.length == a2.length)
           {
@@ -478,11 +470,6 @@
                 return false;
             return true;
           }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
-      }
     return false;
   }
 
@@ -501,8 +488,9 @@
     if (a1 == a2)
       return true;
 
-    try
-      {
+    if (null == a1 || null == a2)
+        return false;
+
         // If they're the same length, test each element
         if (a1.length == a2.length)
           {
@@ -512,11 +500,6 @@
                 return false;
             return true;
           }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
-      }
     return false;
   }
 
@@ -535,8 +518,9 @@
     if (a1 == a2)
       return true;
 
-    try
-      {
+    if (null == a1 || null == a2)
+        return false;
+
         // If they're the same length, test each element
         if (a1.length == a2.length)
           {
@@ -546,11 +530,6 @@
                 return false;
             return true;
           }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
-      }
     return false;
   }
 
@@ -569,8 +548,9 @@
     if (a1 == a2)
       return true;
 
-    try
-      {
+    if (null == a1 || null == a2)
+        return false;
+
         // If they're the same length, test each element
         if (a1.length == a2.length)
           {
@@ -580,11 +560,6 @@
                 return false;
             return true;
           }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
-      }
     return false;
   }
 
@@ -603,9 +578,9 @@
     if (a1 == a2)
       return true;
 
+    if (null == a1 || null == a2)
+        return false;
     // Must use Float.compare to take into account NaN, +-0.
-    try
-      {
         // If they're the same length, test each element
         if (a1.length == a2.length)
           {
@@ -615,11 +590,6 @@
                 return false;
             return true;
           }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
-      }
     return false;
   }
 
@@ -638,9 +608,10 @@
     if (a1 == a2)
       return true;
 
+    if (null == a1 || null == a2)
+        return false;
+    
     // Must use Double.compare to take into account NaN, +-0.
-    try
-      {
         // If they're the same length, test each element
         if (a1.length == a2.length)
           {
@@ -650,11 +621,6 @@
                 return false;
             return true;
           }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
-      }
     return false;
   }
 
@@ -674,8 +640,9 @@
     if (a1 == a2)
       return true;
 
-    try
-      {
+    if (null == a1 || null == a2)
+        return false;
+    
         // If they're the same length, test each element
         if (a1.length == a2.length)
           {
@@ -685,11 +652,6 @@
                 return false;
             return true;
           }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
-      }
     return false;
   }
 

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