summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/internal/AnnotationInfos.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2012-08-16 20:03:14 +0200
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2012-08-20 08:11:06 +0100
commit1ee7ffb6fd2de6e7194a4eb89601d98503b50048 (patch)
treea7395953072397beb1435c4907cf4e23cbb4e469 /src/reflect/scala/reflect/internal/AnnotationInfos.scala
parent0cde930b192acc73d1e0b5951b3300c286ae4dd2 (diff)
downloadscala-1ee7ffb6fd2de6e7194a4eb89601d98503b50048.tar.gz
scala-1ee7ffb6fd2de6e7194a4eb89601d98503b50048.tar.bz2
scala-1ee7ffb6fd2de6e7194a4eb89601d98503b50048.zip
Optimizations to cut down on #closures created
Driven by profile data.
Diffstat (limited to 'src/reflect/scala/reflect/internal/AnnotationInfos.scala')
-rw-r--r--src/reflect/scala/reflect/internal/AnnotationInfos.scala23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/reflect/scala/reflect/internal/AnnotationInfos.scala b/src/reflect/scala/reflect/internal/AnnotationInfos.scala
index 229570dafd..a444c786f7 100644
--- a/src/reflect/scala/reflect/internal/AnnotationInfos.scala
+++ b/src/reflect/scala/reflect/internal/AnnotationInfos.scala
@@ -8,6 +8,7 @@ package internal
import util._
import pickling.ByteCodecs
+import scala.annotation.tailrec
/** AnnotationInfo and its helpers */
trait AnnotationInfos extends api.AnnotationInfos { self: SymbolTable =>
@@ -31,11 +32,27 @@ trait AnnotationInfos extends api.AnnotationInfos { self: SymbolTable =>
case AnnotationInfo(tp, Literal(Constant(tpe: Type)) :: Nil, _) if tp.typeSymbol == ThrowsClass => tpe.typeSymbol
}
- /** Test for, get, or remove an annotation */
- def hasAnnotation(cls: Symbol) = annotations exists (_ matches cls)
- def getAnnotation(cls: Symbol) = annotations find (_ matches cls)
+ /** Tests for, get, or remove an annotation */
+ def hasAnnotation(cls: Symbol): Boolean =
+ //OPT inlined from exists to save on #closures; was: annotations exists (_ matches cls)
+ dropOtherAnnotations(annotations, cls).nonEmpty
+
+ def getAnnotation(cls: Symbol): Option[AnnotationInfo] =
+ //OPT inlined from exists to save on #closures; was: annotations find (_ matches cls)
+ dropOtherAnnotations(annotations, cls) match {
+ case ann :: _ => Some(ann)
+ case _ => None
+ }
+
def removeAnnotation(cls: Symbol): Self = filterAnnotations(ann => !(ann matches cls))
+
final def withAnnotation(annot: AnnotationInfo): Self = withAnnotations(List(annot))
+
+ @tailrec private
+ def dropOtherAnnotations(anns: List[AnnotationInfo], cls: Symbol): List[AnnotationInfo] = anns match {
+ case ann :: rest => if (ann matches cls) anns else dropOtherAnnotations(rest, cls)
+ case Nil => Nil
+ }
}
/** Arguments to classfile annotations (which are written to