a common pattern in the collection code is to create a builder, iterate a collection adding to the builder, and then call result
for the special case of a empty collection this can be optimised to call empty without the generation of the builder
e.g. in GenTraversableFactory
def tabulate[A](n: Int)(f: Int => A): CC[A] = {
val b = newBuilder[A]
b.sizeHint(n)
var i = 0
while (i < n) {
b += f(i)
i += 1
}
b.result()
}
could be
def tabulate[A](n: Int)(f: Int => A): CC[A] = {
if (n == 0) empty else {
val b = newBuilder[A]
b.sizeHint(n)
var i = 0
while (i < n) {
b += f(i)
i += 1
}
b.result()
}
}
(and the same for concat, iterate and fill in GenTraversableFactory) and some others in other places in the libaray code
this optimisation has occurred in several places, but several have not. Should be reviewed, profiled etc
a common pattern in the collection code is to create a builder, iterate a collection adding to the builder, and then call result
for the special case of a empty collection this can be optimised to call empty without the generation of the builder
e.g. in GenTraversableFactory
could be
(and the same for concat, iterate and fill in GenTraversableFactory) and some others in other places in the libaray code
this optimisation has occurred in several places, but several have not. Should be reviewed, profiled etc
Probably several PRs