File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed
compiler/src/dotty/tools/io Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 /**
You can’t perform that action at this time.
0 commit comments