Commits

Stepan Koltsov  committed d460370

trim in filter-to-list

  • Participants
  • Parent commits 500d4b2

Comments (0)

Files changed (1)

File src/java/org/jetbrains/jet/iteratorListPerf/lib/CollectionUtils.java

     }
     
     public static <A> List<A> filterToList(Iterable<A> source, Function<A, Boolean> f) {
-        List<A> result = new ArrayList<A>();
+        ArrayList<A> result;
+        if (source instanceof ArrayList<?>) {
+            result = new ArrayList<A>(((ArrayList<?>) source).size());
+        } else {
+            result = new ArrayList<A>();
+        }
         for (A item : source) {
             if (f.apply(item)) {
                 result.add(item);
             }
         }
+        result.trimToSize();
         return result;
     }
 }