From 139ff44a692f6f35bed715528d38f95a14b8340e Mon Sep 17 00:00:00 2001 From: extempore Date: Mon, 20 Jun 2011 16:08:45 +0000 Subject: [PATCH] Reverts r25085 ("Performance tweaks for AbstractFile, no review.") which apparently is making the IDE refuse to overwrite classfiles. For the life of me I can't find why there should be any difference. Bowing to expedience, no review. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@25117 5e8d7ff9-d8ef-0310-90f0-a4852d11357a --- .../scala/tools/nsc/io/AbstractFile.scala | 62 +++++++++---------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/src/compiler/scala/tools/nsc/io/AbstractFile.scala b/src/compiler/scala/tools/nsc/io/AbstractFile.scala index af4d68e86..e95928ad6 100644 --- a/src/compiler/scala/tools/nsc/io/AbstractFile.scala +++ b/src/compiler/scala/tools/nsc/io/AbstractFile.scala @@ -9,8 +9,6 @@ package io import java.io.{ FileOutputStream, IOException, InputStream, OutputStream, BufferedOutputStream } import java.net.URL -import PartialFunction._ -import java.io.File.{ separatorChar => separator } import scala.collection.mutable.ArrayBuffer /** @@ -84,6 +82,7 @@ object AbstractFile { *

*/ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { + /** Returns the name of this abstract file. */ def name: String @@ -187,47 +186,43 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { * @return ... */ def lookupPath(path: String, directory: Boolean): AbstractFile = { - lookupPathInternal(path, directory, false) + lookup((f, p, dir) => f.lookupName(p, dir), path, directory) } /** Return an abstract file that does not check that `path` denotes * an existing file. */ def lookupPathUnchecked(path: String, directory: Boolean): AbstractFile = { - lookupPathInternal(path, directory, true) - } - - private def lookupPathInternal(path0: String, directory: Boolean, unchecked: Boolean): AbstractFile = { - // trim trailing '/'s - val path = ( - if (path0.charAt(path0.length - 1) != separator) path0 - else path0.substring(0, path0.length - 1) - ) - def loop(file: AbstractFile, start: Int): AbstractFile = { - val index = path.indexOf(separator, start) - if (index < 0) { - if (unchecked) file.lookupNameUnchecked(path, directory) - else file.lookupName(path, directory) - } - else { - val name = path.substring(start, index) - val next = ( - if (unchecked) file.lookupNameUnchecked(name, true) - else file.lookupName(name, true) - ) - if (next == null) null - else loop(next, index + 1) - } - } - loop(this, 0) + lookup((f, p, dir) => f.lookupNameUnchecked(p, dir), path, directory) } - private def fileOrSubdirectoryNamed(name: String, directory: Boolean): AbstractFile = { - val lookup = lookupName(name, directory) + private def lookup(getFile: (AbstractFile, String, Boolean) => AbstractFile, + path0: String, + directory: Boolean): AbstractFile = { + val separator = java.io.File.separatorChar + // trim trailing '/'s + val path: String = if (path0.last == separator) path0 dropRight 1 else path0 + val length = path.length() + assert(length > 0 && !(path.last == separator), path) + var file = this + var start = 0 + while (true) { + val index = path.indexOf(separator, start) + assert(index < 0 || start < index) + val name = path.substring(start, if (index < 0) length else index) + file = getFile(file, name, if (index < 0) directory else true) + if ((file eq null) || index < 0) return file + start = index + 1 + } + file + } + + private def fileOrSubdirectoryNamed(name: String, isDir: Boolean): AbstractFile = { + val lookup = lookupName(name, isDir) if (lookup != null) lookup else { val jfile = new JFile(file, name) - if (directory) jfile.mkdirs() else jfile.createNewFile() + if (isDir) jfile.mkdirs() else jfile.createNewFile() new PlainFile(jfile) } } @@ -254,5 +249,6 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { protected def unsupported(msg: String): Nothing = throw new UnsupportedOperationException(msg) /** Returns the path of this abstract file. */ - override def toString = path + override def toString() = path + }