lib/std: more efficient Collection::to_a
authorJean Privat <jean@pryen.org>
Wed, 6 Aug 2014 19:32:12 +0000 (15:32 -0400)
committerJean Privat <jean@pryen.org>
Wed, 6 Aug 2014 19:32:12 +0000 (15:32 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/collection/array.nit

index 6ae145d..0d69ed6 100644 (file)
@@ -638,7 +638,9 @@ redef class Collection[E]
        # Build a new array from a collection
        fun to_a: Array[E]
        do
-               return iterator.to_a
+               var res = new Array[E].with_capacity(length)
+               res.add_all(self)
+               return res
        end
 end