Skip to content

Commit 16b75fb

Browse files
Merge pull request #9178 from yu-croco/refact_compiler_io
Refactor compiler io resources
2 parents 0ee0557 + 700c5dd commit 16b75fb

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ class Directory(jpath: JPath) extends Path(jpath) {
5959
def files: Iterator[File] = list collect { case x: File => x }
6060

6161
override def walkFilter(cond: Path => Boolean): Iterator[Path] =
62-
list filter cond flatMap (_ walkFilter cond)
62+
list.filter(cond).flatMap(_.walkFilter(cond))
6363

6464
def deepFiles: Iterator[File] = Path.onlyFiles(deepList())
6565

6666
/** If optional depth argument is not given, will recurse
6767
* until it runs out of contents.
6868
*/
6969
def deepList(depth: Int = -1): Iterator[Path] =
70-
if (depth < 0) list ++ (dirs flatMap (_ deepList (depth)))
70+
if (depth < 0) list ++ dirs.flatMap(_.deepList(depth))
7171
else if (depth == 0) Iterator.empty
72-
else list ++ (dirs flatMap (_ deepList (depth - 1)))
72+
else list ++ dirs.flatMap(_.deepList(depth - 1))
7373
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ object Streamable {
125125
finally stream.close()
126126

127127
def bytes(is: => InputStream): Array[Byte] =
128-
(new Bytes {
128+
new Bytes {
129129
def inputStream() = is
130-
}).toByteArray()
130+
}.toByteArray()
131131

132132
def slurp(is: => InputStream)(implicit codec: Codec): String =
133133
new Chars { def inputStream() = is } slurp codec

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extends AbstractFile {
1818
def path: String =
1919
maybeContainer match {
2020
case None => name
21-
case Some(parent) => parent.path+'/'+ name
21+
case Some(parent) => parent.path + '/' + name
2222
}
2323

2424
def absolute: AbstractFile = this
@@ -54,7 +54,7 @@ extends AbstractFile {
5454

5555
override def fileNamed(name: String): AbstractFile =
5656
Option(lookupName(name, directory = false)) getOrElse {
57-
val newFile = new VirtualFile(name, path+'/'+name)
57+
val newFile = new VirtualFile(name, path + '/' + name)
5858
files(name) = newFile
5959
newFile
6060
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.nio.file.Files
1111
import java.util.zip.{ ZipEntry, ZipFile }
1212
import java.util.jar.Manifest
1313
import scala.collection.mutable
14-
import scala.collection.JavaConverters._
14+
import scala.jdk.CollectionConverters._
1515

1616
/** An abstraction for zip files and streams. Everything is written the way
1717
* it is for performance: we come through here a lot on every run. Be careful
@@ -85,7 +85,7 @@ abstract class ZipArchive(override val jpath: JPath) extends AbstractFile with E
8585
}
8686
}
8787

88-
private def ensureDir(dirs: mutable.Map[String, DirEntry], path: String, zipEntry: ZipEntry): DirEntry =
88+
private def ensureDir(dirs: mutable.Map[String, DirEntry], path: String): DirEntry =
8989
//OPT inlined from getOrElseUpdate; saves ~50K closures on test run.
9090
// was:
9191
// dirs.getOrElseUpdate(path, {
@@ -97,16 +97,16 @@ abstract class ZipArchive(override val jpath: JPath) extends AbstractFile with E
9797
dirs get path match {
9898
case Some(v) => v
9999
case None =>
100-
val parent = ensureDir(dirs, dirName(path), null)
100+
val parent = ensureDir(dirs, dirName(path))
101101
val dir = new DirEntry(path, parent)
102102
parent.entries(baseName(path)) = dir
103103
dirs(path) = dir
104104
dir
105105
}
106106

107107
protected def getDir(dirs: mutable.Map[String, DirEntry], entry: ZipEntry): DirEntry = {
108-
if (entry.isDirectory) ensureDir(dirs, entry.getName, entry)
109-
else ensureDir(dirs, dirName(entry.getName), null)
108+
if (entry.isDirectory) ensureDir(dirs, entry.getName)
109+
else ensureDir(dirs, dirName(entry.getName))
110110
}
111111
}
112112
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
@@ -240,8 +240,8 @@ final class ManifestResources(val url: URL) extends ZipArchive(null) {
240240
private def resourceInputStream(path: String): InputStream = {
241241
new FilterInputStream(null) {
242242
override def read(): Int = {
243-
if(in == null) in = Thread.currentThread().getContextClassLoader().getResourceAsStream(path)
244-
if(in == null) throw new RuntimeException(path + " not found")
243+
if (in == null) in = Thread.currentThread().getContextClassLoader().getResourceAsStream(path)
244+
if (in == null) throw new RuntimeException(path + " not found")
245245
super.read()
246246
}
247247

0 commit comments

Comments
 (0)