Author: mbenson
Date: Sun Jul 17 00:43:55 2011
New Revision: 1147508

URL: http://svn.apache.org/viewvc?rev=1147508&view=rev
Log:
reduce number of created arrays

Modified:
    
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java

Modified: 
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java?rev=1147508&r1=1147507&r2=1147508&view=diff
==============================================================================
--- 
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
 (original)
+++ 
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
 Sun Jul 17 00:43:55 2011
@@ -5019,7 +5019,7 @@ public class ArrayUtils {
                 toRemove.add(found++);
             }
         }
-        return removeAll(array, toPrimitive(toRemove.toArray(new 
Integer[toRemove.size()])));
+        return removeAll(array, extractIndices(toRemove));
     }
 
     /**
@@ -5109,7 +5109,7 @@ public class ArrayUtils {
                 toRemove.add(found++);
             }
         }
-        return removeAll(array, toPrimitive(toRemove.toArray(new 
Integer[toRemove.size()])));
+        return removeAll(array, extractIndices(toRemove));
     }
 
     /**
@@ -5199,7 +5199,7 @@ public class ArrayUtils {
                 toRemove.add(found++);
             }
         }
-        return removeAll(array, toPrimitive(toRemove.toArray(new 
Integer[toRemove.size()])));
+        return removeAll(array, extractIndices(toRemove));
     }
 
     /**
@@ -5289,7 +5289,7 @@ public class ArrayUtils {
                 toRemove.add(found++);
             }
         }
-        return removeAll(array, toPrimitive(toRemove.toArray(new 
Integer[toRemove.size()])));
+        return removeAll(array, extractIndices(toRemove));
     }
 
     /**
@@ -5379,7 +5379,7 @@ public class ArrayUtils {
                 toRemove.add(found++);
             }
         }
-        return removeAll(array, toPrimitive(toRemove.toArray(new 
Integer[toRemove.size()])));
+        return removeAll(array, extractIndices(toRemove));
     }
 
     /**
@@ -5469,7 +5469,7 @@ public class ArrayUtils {
                 toRemove.add(found++);
             }
         }
-        return removeAll(array, toPrimitive(toRemove.toArray(new 
Integer[toRemove.size()])));
+        return removeAll(array, extractIndices(toRemove));
     }
 
     /**
@@ -5559,7 +5559,7 @@ public class ArrayUtils {
                 toRemove.add(found++);
             }
         }
-        return removeAll(array, toPrimitive(toRemove.toArray(new 
Integer[toRemove.size()])));
+        return removeAll(array, extractIndices(toRemove));
     }
 
     /**
@@ -5649,7 +5649,7 @@ public class ArrayUtils {
                 toRemove.add(found++);
             }
         }
-        return removeAll(array, toPrimitive(toRemove.toArray(new 
Integer[toRemove.size()])));
+        return removeAll(array, extractIndices(toRemove));
     }
 
     /**
@@ -5735,7 +5735,7 @@ public class ArrayUtils {
                 toRemove.add(found++);
             }
         }
-        return removeAll(array, toPrimitive(toRemove.toArray(new 
Integer[toRemove.size()])));
+        return removeAll(array, extractIndices(toRemove));
     }
 
     /**
@@ -5786,4 +5786,12 @@ public class ArrayUtils {
         return result;
     }
 
+    private static int[] extractIndices(HashSet<Integer> coll) {
+        int[] result = new int[coll.size()];
+        int i = 0;
+        for (Integer index : coll) {
+            result[i++] = index.intValue();
+        }
+        return result;
+    }
 }


Reply via email to