Revert toArrayList for primitive arrays back to trivial implementation.

Use newly introduced Int.MAX_VALUE in JS.
Inline mapCapacityForValues function.
Precalculate capacity of linked hash set being created with toMutableSet function.
This commit is contained in:
Ilya Gorbunov
2015-05-12 16:05:03 +03:00
parent 7ce0487b7e
commit 85e637b1e7
6 changed files with 59 additions and 31 deletions
@@ -19,7 +19,7 @@ fun sets(): List<GenericFunction> {
}
body(ArraysOfObjects, ArraysOfPrimitives) {
"""
val set = LinkedHashSet<T>(size())
val set = LinkedHashSet<T>(mapCapacity(size()))
for (item in this) set.add(item)
return set
"""
@@ -48,9 +48,23 @@ fun snapshots(): List<GenericFunction> {
doc { "Returns an ArrayList of all elements" }
returns("ArrayList<T>")
body { "return toCollection(ArrayList<T>())" }
body(Iterables) {
"""
if (this is Collection<T>)
return this.toArrayList()
return toCollection(ArrayList<T>())
"""
}
body(Collections) { "return ArrayList(this)" }
body(Strings) { "return toCollection(ArrayList<T>(length()))" }
body(ArraysOfObjects, ArraysOfPrimitives) { "return this.asList().toArrayList()" }
body(ArraysOfObjects) { "return this.asList().toArrayList()" }
body(ArraysOfPrimitives) {
"""
val list = ArrayList<T>(size())
for (item in this) list.add(item)
return list
"""
}
}
templates add f("toList()") {