summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-11-24 01:24:47 +0000
committerPaul Phillips <paulp@improving.org>2011-11-24 01:24:47 +0000
commit93717598b711a69822d802e06873ed7b00f89898 (patch)
tree88df749931a2a05a99c67b5d845d0fa572927a1a /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parent60fb9ec19b50cd8059122ccffd72014b3eefc51f (diff)
downloadscala-93717598b711a69822d802e06873ed7b00f89898.tar.gz
scala-93717598b711a69822d802e06873ed7b00f89898.tar.bz2
scala-93717598b711a69822d802e06873ed7b00f89898.zip
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.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala24
1 files changed, 17 insertions, 7 deletions
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