diff options
author | Paul Phillips <paulp@improving.org> | 2011-05-09 19:07:40 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-05-09 19:07:40 +0000 |
commit | 1a92fb60e6853fca4b4e5bd0d03f913c300100ae (patch) | |
tree | b287e88e828d2dd788d6b9c1bb0242ae4f03c21b /src/compiler/scala/tools/nsc/util/ClassPath.scala | |
parent | 41ac77599ce022087ec595b6da4874b39472019b (diff) | |
download | scala-1a92fb60e6853fca4b4e5bd0d03f913c300100ae.tar.gz scala-1a92fb60e6853fca4b4e5bd0d03f913c300100ae.tar.bz2 scala-1a92fb60e6853fca4b4e5bd0d03f913c300100ae.zip |
Another round of optimization.
exciting as the original, but not a bad way to spend a rainy afternoon.
Most changes involve files and paths, which are we find exercised rather
heavily at startup. This patch takes about 15 seconds off my time to
build quick. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/ClassPath.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/util/ClassPath.scala | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala index e1cf6e55d9..c3731150c4 100644 --- a/src/compiler/scala/tools/nsc/util/ClassPath.scala +++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala @@ -8,7 +8,7 @@ package scala.tools.nsc package util import java.net.URL -import scala.collection.mutable +import scala.collection.{ mutable, immutable } import io.{ File, Directory, Path, Jar, AbstractFile, ClassAndJarInfo } import scala.tools.util.StringOps.splitWhere import Jar.isJarOrZip @@ -103,8 +103,10 @@ object ClassPath { /** Expand dir out to contents, a la extdir */ def expandDir(extdir: String): List[String] = { - val dir = Option(AbstractFile getDirectory extdir) getOrElse (return Nil) - dir filter (_.isClassContainer) map (dir.sfile.get / _.name path) toList + AbstractFile getDirectory extdir match { + case null => Nil + case dir => dir filter (_.isClassContainer) map (x => new java.io.File(dir.file, x.name) getPath) toList + } } /** A useful name filter. */ @@ -298,7 +300,10 @@ abstract class ClassPath[T] { class SourcePath[T](dir: AbstractFile, val context: ClassPathContext[T]) extends ClassPath[T] { def name = dir.name override def origin = dir.underlyingSource map (_.path) - def asURLs = dir.sfile.toList map (_.toURL) + def asURLs = dir.file match { + case null => Nil + case file => File(file).toURL :: Nil + } def asClasspathString = dir.path val sourcepaths: IndexedSeq[AbstractFile] = IndexedSeq(dir) @@ -321,19 +326,30 @@ class SourcePath[T](dir: AbstractFile, val context: ClassPathContext[T]) extends class DirectoryClassPath(val dir: AbstractFile, val context: ClassPathContext[AbstractFile]) extends ClassPath[AbstractFile] { def name = dir.name override def origin = dir.underlyingSource map (_.path) - def asURLs = dir.sfile.toList map (_.toURL) + def asURLs = dir.file match { + case null => Nil + case file => File(file).toURL :: Nil + } def asClasspathString = dir.path val sourcepaths: IndexedSeq[AbstractFile] = IndexedSeq() - lazy val classes: IndexedSeq[ClassRep] = dir flatMap { f => - if (f.isDirectory || !validClassFile(f.name)) Nil - else List(ClassRep(Some(f), None)) - } toIndexedSeq + lazy val classes: IndexedSeq[ClassRep] = { + val buf = immutable.Vector.newBuilder[ClassRep] + dir foreach { f => + if (!f.isDirectory && validClassFile(f.name)) + buf += ClassRep(Some(f), None) + } + buf.result + } - lazy val packages: IndexedSeq[DirectoryClassPath] = dir flatMap { f => - if (f.isDirectory && validPackage(f.name)) List(new DirectoryClassPath(f, context)) - else Nil - } toIndexedSeq + lazy val packages: IndexedSeq[DirectoryClassPath] = { + val buf = immutable.Vector.newBuilder[DirectoryClassPath] + dir foreach { f => + if (f.isDirectory && validPackage(f.name)) + buf += new DirectoryClassPath(f, context) + } + buf.result + } override def toString() = "directory classpath: "+ dir } |