From 93717598b711a69822d802e06873ed7b00f89898 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 24 Nov 2011 01:24:47 +0000 Subject: Optimization of typedArgs. Keep seeing what might be our single use of Tuple3#zipped so high in the profiling output. I don't think it's zipped3's fault, more that it figures prominently in a major consumer of compile time, but it's not going to hurt to send it on its merry way. --- .../scala/tools/nsc/typechecker/Typers.scala | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index b09309f056..ee1d29a07d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2166,14 +2166,24 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { def typedArgs(args: List[Tree], mode: Int) = args mapConserve (arg => typedArg(arg, mode, 0, WildcardType)) - def typedArgs(args: List[Tree], mode: Int, originalFormals: List[Type], adaptedFormals: List[Type]) = { - var newmodes = originalFormals map (tp => if (isByNameParamType(tp)) 0 else BYVALmode) - if (isVarArgTypes(originalFormals)) // TR check really necessary? - newmodes = newmodes.init ++ List.fill(args.length - originalFormals.length + 1)(STARmode | BYVALmode) - - (args, adaptedFormals, newmodes).zipped map { (arg, formal, m) => - typedArg(arg, mode, m, formal) + def typedArgs(args0: List[Tree], mode: Int, formals0: List[Type], adapted0: List[Type]): List[Tree] = { + val sticky = onlyStickyModes(mode) + def loop(args: List[Tree], formals: List[Type], adapted: List[Type]): List[Tree] = { + if (args.isEmpty || adapted.isEmpty) Nil + else { + // No formals left or * indicates varargs. + val isVarArgs = formals.isEmpty || formals.tail.isEmpty && isRepeatedParamType(formals.head) + val typedMode = sticky | ( + if (isVarArgs) STARmode | BYVALmode + else if (isByNameParamType(formals.head)) 0 + else BYVALmode + ) + val tree = typedArg(args.head, mode, typedMode, adapted.head) + // formals may be empty, so don't call tail + tree :: loop(args.tail, formals drop 1, adapted.tail) + } } + loop(args0, formals0, adapted0) } /** Does function need to be instantiated, because a missing parameter -- cgit v1.2.3