Permalink
Browse files

More batched performance improvements for io.{ ...

More batched performance improvements for io.{ File, Classpath } and
others in the neighborhood.  Avoids calling the expensive
getCanonicalPath in favor of getAbsolutePath: I note that because
it has the potential to change compiler behavior at the borders.
No review.
  • Loading branch information...
1 parent 7fa4ca9 commit e4f800b20550b62d5186130c6f06281f3df3ed90 @paulp paulp committed Jun 14, 2011
@@ -615,7 +615,7 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
file
}
- val res = execWithArgFiles(java, List(writeSettings.getCanonicalPath))
+ val res = execWithArgFiles(java, List(writeSettings.getAbsolutePath))
if (failonerror && res != 0)
buildError("Compilation failed because of an internal compiler error;"+
" see the error output for details.")
@@ -17,14 +17,14 @@ import java.nio.channels.{ Channel, FileChannel }
import scala.io.Codec
object File {
- def pathSeparator = JFile.pathSeparator
- def separator = JFile.separator
+ def pathSeparator = java.io.File.pathSeparator
+ def separator = java.io.File.separator
def apply(path: Path)(implicit codec: Codec) = new File(path.jfile)(codec)
// Create a temporary file, which will be deleted upon jvm exit.
def makeTemp(prefix: String = Path.randomPrefix, suffix: String = null, dir: JFile = null) = {
- val jfile = JFile.createTempFile(prefix, suffix, dir)
+ val jfile = java.io.File.createTempFile(prefix, suffix, dir)
jfile.deleteOnExit()
apply(jfile)
}
@@ -48,7 +48,7 @@ object File {
//
// try {
// import Streamable.closing
- // val tmp = JFile.createTempFile("bug6503430", null, null)
+ // val tmp = java.io.File.createTempFile("bug6503430", null, null)
// try closing(new FileInputStream(tmp)) { in =>
// val inc = in.getChannel()
// closing(new FileOutputStream(tmp, true)) { out =>
@@ -65,9 +65,9 @@ object Path {
def onlyFiles(xs: Iterator[Path]): Iterator[File] = xs filter (_.isFile) map (_.toFile)
def onlyFiles(xs: List[Path]): List[File] = xs filter (_.isFile) map (_.toFile)
- def roots: List[Path] = JFile.listRoots().toList map Path.apply
+ def roots: List[Path] = java.io.File.listRoots().toList map Path.apply
- def apply(segments: Seq[String]): Path = apply(segments mkString JFile.separator)
+ def apply(segments: Seq[String]): Path = apply(segments mkString java.io.File.separator)
def apply(path: String): Path = apply(new JFile(path))
def apply(jfile: JFile): Path =
if (jfile.isFile) new File(jfile)
@@ -84,8 +84,8 @@ import Path._
* semantics regarding how a Path might relate to the world.
*/
class Path private[io] (val jfile: JFile) {
- val separator = JFile.separatorChar
- val separatorStr = JFile.separator
+ val separator = java.io.File.separatorChar
+ val separatorStr = java.io.File.separator
// Validation: this verifies that the type of this object and the
// contents of the filesystem are in agreement. All objects are
@@ -130,7 +130,7 @@ class Path private[io] (val jfile: JFile) {
// identity
def name: String = jfile.getName()
def path: String = jfile.getPath()
- def normalize: Path = Path(jfile.getCanonicalPath())
+ def normalize: Path = Path(jfile.getAbsolutePath())
def isRootPath: Boolean = roots exists (_ isSame this)
def resolve(other: Path) = if (other.isAbsolute || isEmpty) other else /(other)
@@ -11,16 +11,7 @@ import java.util.jar.{ Attributes }
package object io {
type JManifest = java.util.jar.Manifest
- private[io] type JFile = java.io.File
- // grimly bulldozing through #4338
- private[io] object JFile {
- import java.io.{ File => JJFile } // the irony of JFile being ambiguous is not overlooked
- val createTempFile = JJFile.createTempFile(_: String, _: String, _: JFile)
- def pathSeparator = JJFile.pathSeparator
- def separator = JJFile.separator
- def separatorChar = JJFile.separatorChar
- def listRoots() = JJFile.listRoots()
- }
+ type JFile = java.io.File
private[io] implicit def installManifestOps(m: JManifest) = new ManifestOps(m)
class ManifestOps(manifest: JManifest) {
def attrs = manifest.getMainAttributes()
@@ -165,7 +165,7 @@ object ClassPath {
class JavaContext extends ClassPathContext[AbstractFile] {
def toBinaryName(rep: AbstractFile) = {
val name = rep.name
- assert(name.length > 6 && name.substring(name.length - 6) == ".class", name)
+ assert(endsClass(name), name)
name.substring(0, name.length - 6)
}
def newClassPath(dir: AbstractFile) = new DirectoryClassPath(dir, this)
@@ -175,16 +175,18 @@ object ClassPath {
override def isValidName(name: String) = !isTraitImplementation(name)
}
+ @inline private def endsClass(s: String) = s.length > 6 && s.substring(s.length - 6) == ".class"
+ @inline private def endsScala(s: String) = s.length > 6 && s.substring(s.length - 6) == ".scala"
+ @inline private def endsJava(s: String) = s.length > 5 && s.substring(s.length - 5) == ".java"
+
/** From the source file to its identifier.
*/
def toSourceName(f: AbstractFile): String = {
val name = f.name
- if (name.length > 6 && name.substring(name.length - 6) == ".scala")
- name.substring(0, name.length - 6)
- else if (name.length > 5 && name.substring(name.length - 5) == ".java")
- name.substring(0, name.length - 5)
- else
- throw new FatalError("Unexpected source file ending: " + name)
+
+ if (endsScala(name)) name.substring(0, name.length - 6)
+ else if (endsJava(name)) name.substring(0, name.length - 5)
+ else throw new FatalError("Unexpected source file ending: " + name)
}
}
import ClassPath._
@@ -259,10 +261,9 @@ abstract class ClassPath[T] {
/** Filters for assessing validity of various entities.
*/
- def validClassFile(name: String) = (name endsWith ".class") && context.isValidName(name)
- def validPackage(name: String) = (name != "META-INF") && (name != "") && (name(0) != '.')
- def validSourceFile(name: String) = validSourceExtensions exists (name endsWith _)
- def validSourceExtensions = List(".scala", ".java")
+ def validClassFile(name: String) = endsClass(name) && context.isValidName(name)
+ def validPackage(name: String) = (name != "META-INF") && (name != "") && (name.charAt(0) != '.')
+ def validSourceFile(name: String) = endsScala(name) || endsJava(name)
/**
* Find a ClassRep given a class name of the form "package.subpackage.ClassName".
@@ -291,7 +292,7 @@ abstract class ClassPath[T] {
case x: ClassPath[_] => this.sortString == x.sortString
case _ => false
}
- override def hashCode = sortString.##
+ override def hashCode = sortString.hashCode()
}
/**
@@ -300,10 +301,7 @@ 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.file match {
- case null => Nil
- case file => File(file).toURL :: Nil
- }
+ def asURLs = if (dir.file == null) Nil else List(dir.toURL)
def asClasspathString = dir.path
val sourcepaths: IndexedSeq[AbstractFile] = IndexedSeq(dir)
@@ -329,10 +327,7 @@ 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.file match {
- case null => Nil
- case file => File(file).toURL :: Nil
- }
+ def asURLs = if (dir.file == null) Nil else List(dir.toURL)
def asClasspathString = dir.path
val sourcepaths: IndexedSeq[AbstractFile] = IndexedSeq()
@@ -143,7 +143,7 @@ class ConsoleRunner extends DirectRunner {
val dir =
if (fileManager.testClasses.isDefined) fileManager.testClassesDir
else fileManager.testBuildFile getOrElse {
- fileManager.latestCompFile.getParentFile.getParentFile.getCanonicalFile
+ fileManager.latestCompFile.getParentFile.getParentFile.getAbsoluteFile
}
val vmBin = javaHome + File.separator + "bin"
@@ -27,7 +27,7 @@ trait FileManager {
*/
def compareFiles(f1: File, f2: File): String = {
val diffWriter = new StringWriter
- val args = Array(f1.getCanonicalPath(), f2.getCanonicalPath())
+ val args = Array(f1.getAbsolutePath(), f2.getAbsolutePath())
DiffPrint.doDiff(args, diffWriter)
val res = diffWriter.toString
@@ -525,7 +525,7 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
val succFn: (File, File) => Boolean = { (logFile, outDir) =>
NestUI.verbose("compilation of "+file+" succeeded\n")
- val outURL = outDir.getCanonicalFile.toURI.toURL
+ val outURL = outDir.getAbsoluteFile.toURI.toURL
val logWriter = new PrintStream(new FileOutputStream(logFile), true)
Output.withRedirected(logWriter) {
@@ -616,7 +616,7 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
// create proper settings for the compiler
val settings = new Settings(workerError)
- settings.outdir.value = outDir.getCanonicalFile.getAbsolutePath
+ settings.outdir.value = outDir.getAbsoluteFile.getAbsolutePath
settings.sourcepath.value = sourcepath
settings.classpath.value = fileManager.CLASSPATH
settings.Ybuildmanagerdebug.value = true
@@ -723,12 +723,12 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
// run compiler in resident mode
// $SCALAC -d "$os_dstbase".obj -Xresident -sourcepath . "$@"
- val sourcedir = logFile.getParentFile.getCanonicalFile
+ val sourcedir = logFile.getParentFile.getAbsoluteFile
val sourcepath = sourcedir.getAbsolutePath+File.separator
NestUI.verbose("sourcepath: "+sourcepath)
val argString =
- "-d "+outDir.getCanonicalFile.getAbsolutePath+
+ "-d "+outDir.getAbsoluteFile.getPath+
" -Xresident"+
" -sourcepath "+sourcepath
val argList = argString split ' ' toList
@@ -976,7 +976,7 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
react {
case Timeout(file) =>
- updateStatus(file.getCanonicalPath, TestState.Timeout)
+ updateStatus(file.getAbsolutePath, TestState.Timeout)
val swr = new StringWriter
val wr = new PrintWriter(swr, true)
printInfoStart(file, wr)
@@ -988,7 +988,7 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
case Result(file, logs) =>
val state = if (succeeded) TestState.Ok else TestState.Fail
- updateStatus(file.getCanonicalPath, state)
+ updateStatus(file.getAbsolutePath, state)
reportResult(
state,
logs.file,

0 comments on commit e4f800b

Please sign in to comment.