File tree 2 files changed +11
-8
lines changed
compiler/src/dotty/tools/io
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) {
49
49
/** An iterator over the contents of this directory.
50
50
*/
51
51
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
+ }
54
56
55
57
def dirs : Iterator [Directory ] = list collect { case x : Directory => x }
56
58
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 {
55
55
56
56
/** Returns all abstract subfiles of this abstract directory. */
57
57
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
64
63
}
64
+ if (! isDirectory) Iterator .empty
65
+ else givenPath.toDirectory.list filter existsFast map (new PlainFile (_))
65
66
}
66
67
67
68
/**
You can’t perform that action at this time.
0 commit comments