Skip to content

Commit 45a6a48

Browse files
committed
Fix #3450: Partial revert of 7ff1cb6
1 parent ed2feb2 commit 45a6a48

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

compiler/src/dotty/tools/io/Directory.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ class Directory(jpath: JPath) extends Path(jpath) {
4949
/** An iterator over the contents of this directory.
5050
*/
5151
def list: Iterator[Path] =
52-
if (isDirectory) Files.list(jpath).iterator.asScala.map(Path.apply)
53-
else Iterator.empty
52+
jpath.toFile.listFiles match {
53+
case null => Iterator.empty
54+
case xs => xs.iterator.map(x => Path(x.toPath))
55+
}
5456

5557
def dirs: Iterator[Directory] = list collect { case x: Directory => x }
5658
def files: Iterator[File] = list collect { case x: File => x }

compiler/src/dotty/tools/io/PlainFile.scala

+7-6
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
5555

5656
/** Returns all abstract subfiles of this abstract directory. */
5757
def iterator: Iterator[AbstractFile] = {
58-
try {
59-
import scala.collection.JavaConverters._
60-
val it = Files.newDirectoryStream(jpath).iterator()
61-
it.asScala.map(p => new PlainFile(Path(p)))
62-
} catch {
63-
case _: NotDirectoryException => Iterator.empty
58+
// Optimization: Assume that the file was not deleted and did not have permissions changed
59+
// between the call to `list` and the iteration. This saves a call to `exists`.
60+
def existsFast(path: Path) = path match {
61+
case (_: Directory | _: io.File) => true
62+
case _ => path.exists
6463
}
64+
if (!isDirectory) Iterator.empty
65+
else givenPath.toDirectory.list filter existsFast map (new PlainFile(_))
6566
}
6667

6768
/**

0 commit comments

Comments
 (0)