From 57c40c54d6119c42e256d6f7c4c7681a5257b266 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 30 Nov 2012 11:04:58 +0100 Subject: Eliminate allocations in Specialize. --- src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index 173ca1e628..116b6ab58f 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -10,6 +10,7 @@ import scala.tools.nsc.symtab.Flags import scala.collection.{ mutable, immutable } import scala.language.postfixOps import scala.language.existentials +import scala.annotation.tailrec /** Specialize code on types. * @@ -403,11 +404,11 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { case _ => false }) def specializedTypeVars(tpes: List[Type]): immutable.Set[Symbol] = { - if (tpes.isEmpty) immutable.Set.empty else { - val buf = Set.newBuilder[Symbol] - tpes foreach (tp => buf ++= specializedTypeVars(tp)) - buf.result + @tailrec def loop(result: immutable.Set[Symbol], xs: List[Type]): immutable.Set[Symbol] = { + if (xs.isEmpty) result + else loop(result ++ specializedTypeVars(xs.head), xs.tail) } + loop(immutable.Set.empty, tpes) } def specializedTypeVars(sym: Symbol): immutable.Set[Symbol] = ( if (definitions.neverHasTypeParameters(sym)) immutable.Set.empty -- cgit v1.2.3