diff options
author | Paul Phillips <paulp@improving.org> | 2012-11-30 04:42:29 +0100 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-12-27 15:47:31 -0800 |
commit | d3099c0d3ef363f4f1815409051da2edfec81f30 (patch) | |
tree | b6fd3761d1456a0b32ac4dcd54ac737905d40a30 | |
parent | 78269a68d04d57e65ff0403edb6e06440ea74f7d (diff) | |
download | scala-d3099c0d3ef363f4f1815409051da2edfec81f30.tar.gz scala-d3099c0d3ef363f4f1815409051da2edfec81f30.tar.bz2 scala-d3099c0d3ef363f4f1815409051da2edfec81f30.zip |
Eliminating allocations in typeDepth.
-rw-r--r-- | src/reflect/scala/reflect/internal/Types.scala | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index 282d7e18ac..599bc2e264 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -5021,19 +5021,19 @@ trait Types extends api.Types { self: SymbolTable => /** The maximum depth of type `tp` */ def typeDepth(tp: Type): Int = tp match { case TypeRef(pre, sym, args) => - typeDepth(pre) max typeDepth(args) + 1 + math.max(typeDepth(pre), typeDepth(args) + 1) case RefinedType(parents, decls) => - typeDepth(parents) max typeDepth(decls.toList.map(_.info)) + 1 + math.max(typeDepth(parents), symTypeDepth(decls.toList) + 1) case TypeBounds(lo, hi) => - typeDepth(lo) max typeDepth(hi) + math.max(typeDepth(lo), typeDepth(hi)) case MethodType(paramtypes, result) => typeDepth(result) case NullaryMethodType(result) => typeDepth(result) case PolyType(tparams, result) => - typeDepth(result) max typeDepth(tparams map (_.info)) + 1 + math.max(typeDepth(result), symTypeDepth(tparams) + 1) case ExistentialType(tparams, result) => - typeDepth(result) max typeDepth(tparams map (_.info)) + 1 + math.max(typeDepth(result), symTypeDepth(tparams) + 1) case _ => 1 } @@ -5045,13 +5045,14 @@ trait Types extends api.Types { self: SymbolTable => // for (tp <- tps) d = d max by(tp) //!!!OPT!!! // d def loop(tps: List[Type], acc: Int): Int = tps match { - case tp :: rest => loop(rest, acc max by(tp)) - case _ => acc + case tp :: rest => loop(rest, math.max(acc, by(tp))) + case _ => acc } loop(tps, 0) } - private def typeDepth(tps: List[Type]): Int = maxDepth(tps, typeDepth) + private def symTypeDepth(syms: List[Symbol]): Int = typeDepth(syms map (_.info)) + private def typeDepth(tps: List[Type]): Int = maxDepth(tps, typeDepth) private def baseTypeSeqDepth(tps: List[Type]): Int = maxDepth(tps, _.baseTypeSeqDepth) /** Is intersection of given types populated? That is, |