Skip to content

Commit edb2c2f

Browse files
authored
Merge pull request scala/scala#8789 from mkeskells/2.12.x_SeqList1
avoid creation of ListBuffers for Seq.empty and Seq()
2 parents 2ab3e89 + 4c85406 commit edb2c2f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

library/src/scala/collection/generic/GenericCompanion.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ abstract class GenericCompanion[+CC[X] <: GenTraversable[X]] {
3939
/** An empty collection of type `$Coll[A]`
4040
* @tparam A the type of the ${coll}'s elements
4141
*/
42-
def empty[A]: CC[A] = newBuilder[A].result()
42+
def empty[A]: CC[A] = {
43+
if ((this eq immutable.Seq) || (this eq collection.Seq)) Nil.asInstanceOf[CC[A]]
44+
else newBuilder[A].result()
45+
}
4346

4447
/** Creates a $coll with the specified elements.
4548
* @tparam A the type of the ${coll}'s elements

0 commit comments

Comments
 (0)