From ff86078200fea24ad86b402438058fef032ec73f Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 1 Nov 2010 19:03:35 +0000 Subject: Sprinkling in some names to avoid reflective ca... Sprinkling in some names to avoid reflective calls in the compiler as suggested by magarcia. Closes #3974, no review. --- src/compiler/scala/tools/nsc/io/ZipArchive.scala | 10 +++++++--- src/compiler/scala/tools/nsc/transform/Erasure.scala | 3 +-- src/compiler/scala/tools/nsc/util/CharArrayReader.scala | 4 +++- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/io/ZipArchive.scala b/src/compiler/scala/tools/nsc/io/ZipArchive.scala index 21ec95d338..4a1ed2e67b 100644 --- a/src/compiler/scala/tools/nsc/io/ZipArchive.scala +++ b/src/compiler/scala/tools/nsc/io/ZipArchive.scala @@ -47,7 +47,11 @@ object ZipArchive { */ def fromURL(url: URL): AbstractFile = new URLZipArchive(url) - private[io] class ZipEntryTraversableClass(in: InputStream) extends Traversable[ZipEntry] { + private[io] trait ZipTrav extends Traversable[ZipEntry] { + def zis: () => ZipInputStream + } + + private[io] class ZipEntryTraversableClass(in: InputStream) extends ZipTrav { val zis = () => new ZipInputStream(in) def foreach[U](f: ZipEntry => U) = { @@ -72,6 +76,7 @@ object ZipArchive { } } } +import ZipArchive.ZipTrav /** This abstraction aims to factor out the common code between * ZipArchive (backed by a zip file) and URLZipArchive (backed @@ -81,7 +86,6 @@ private[io] trait ZipContainer extends AbstractFile { /** Abstract types */ type SourceType // InputStream or AbstractFile type CreationType // InputStream or ZipFile - type ZipTrav = Traversable[ZipEntry] { def zis: () => ZipInputStream } /** Abstract values */ protected val creationSource: CreationType @@ -245,7 +249,7 @@ final class ZipArchive(file: File, val archive: ZipFile) extends PlainFile(file) } private def zipTraversableFromZipFile(z: ZipFile): ZipTrav = - new Iterable[ZipEntry] { + new Iterable[ZipEntry] with ZipTrav { def zis: () => ZipInputStream = null // not valid for this type def iterator = new Iterator[ZipEntry] { val enum = z.entries() diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 3aa723bcfd..cfd78b7b08 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -114,8 +114,7 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast. * * */ - val erasure = new TypeMap { - + object erasure extends TypeMap { // Compute the dominant part of the intersection type with given `parents` according to new spec. def intersectionDominator(parents: List[Type]): Type = if (parents.isEmpty) ObjectClass.tpe diff --git a/src/compiler/scala/tools/nsc/util/CharArrayReader.scala b/src/compiler/scala/tools/nsc/util/CharArrayReader.scala index 907622e31f..4f4c9a1e13 100644 --- a/src/compiler/scala/tools/nsc/util/CharArrayReader.scala +++ b/src/compiler/scala/tools/nsc/util/CharArrayReader.scala @@ -100,7 +100,9 @@ abstract class CharArrayReader { self => } /** A new reader that takes off at the current character position */ - def lookaheadReader = new CharArrayReader { + def lookaheadReader = new CharArrayLookaheadReader + + class CharArrayLookaheadReader extends CharArrayReader { val buf = self.buf charOffset = self.charOffset ch = self.ch -- cgit v1.2.3