Skip to content

Commit 3e60027

Browse files
committed
Use mutable.HashMap which is fater than j.u.HashMap
1 parent 3f37627 commit 3e60027

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

compiler/src/dotty/tools/dotc/classpath/AggregateClassPath.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
107107
private def mergeClassesAndSources(entries: scala.collection.Seq[ClassRepresentation]): Seq[ClassRepresentation] = {
108108
// based on the implementation from MergedClassPath
109109
var count = 0
110-
val indices = new java.util.HashMap[String, Int]((entries.size * 1.25).toInt)
110+
val indices = new collection.mutable.HashMap[String, Int]()
111111
val mergedEntries = new ArrayBuffer[ClassRepresentation](entries.size)
112112
for {
113113
entry <- entries
114114
} {
115115
val name = entry.name
116-
if (indices.containsKey(name)) {
117-
val index = indices.get(name)
116+
if (indices.contains(name)) {
117+
val index = indices(name)
118118
val existing = mergedEntries(index)
119119

120120
if (existing.binary.isEmpty && entry.binary.isDefined)
@@ -123,12 +123,12 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
123123
mergedEntries(index) = ClassAndSourceFilesEntry(existing.binary.get, entry.source.get)
124124
}
125125
else {
126-
indices.put(name, count)
126+
indices(name) = count
127127
mergedEntries += entry
128128
count += 1
129129
}
130130
}
131-
if (mergedEntries isEmpty) Nil else mergedEntries.toIndexedSeq
131+
if (mergedEntries.isEmpty) Nil else mergedEntries.toIndexedSeq
132132
}
133133

134134
private def getDistinctEntries[EntryType <: ClassRepresentation](getEntries: ClassPath => Seq[EntryType]): Seq[EntryType] = {

compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ trait ZipArchiveFileLookup[FileEntryType <: ClassRepresentation] extends Efficie
6262
}
6363

6464
private def findDirEntry(pkg: PackageName): Option[archive.DirEntry] =
65-
Option(archive.allDirs.get(pkg.dirPathTrailingSlash))
65+
archive.allDirs.get(pkg.dirPathTrailingSlash)
6666

6767
protected def createFileEntry(file: FileZipArchive#Entry): FileEntryType
6868
protected def isRequiredFileType(file: AbstractFile): Boolean

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ abstract class ZipArchive(override val jpath: JPath) extends AbstractFile with E
8585
}
8686
}
8787

88-
private def ensureDir(dirs: java.util.Map[String, DirEntry], path: String): 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, {
@@ -95,16 +95,16 @@ abstract class ZipArchive(override val jpath: JPath) extends AbstractFile with E
9595
// dir
9696
// })
9797
dirs get path match {
98-
case null =>
98+
case Some(v) => v
99+
case None =>
99100
val parent = ensureDir(dirs, dirName(path))
100101
val dir = new DirEntry(path, parent)
101102
parent.entries(baseName(path)) = dir
102-
dirs.put(path, dir)
103+
dirs(path) = dir
103104
dir
104-
case v => v
105105
}
106106

107-
protected def getDir(dirs: java.util.Map[String, DirEntry], entry: ZipEntry): DirEntry = {
107+
protected def getDir(dirs: mutable.Map[String, DirEntry], entry: ZipEntry): DirEntry = {
108108
if (entry.isDirectory) ensureDir(dirs, entry.getName)
109109
else ensureDir(dirs, dirName(entry.getName))
110110
}
@@ -149,9 +149,9 @@ final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) {
149149
override def sizeOption: Option[Int] = Some(zipEntry.getSize.toInt)
150150
}
151151

152-
@volatile lazy val (root, allDirs): (DirEntry, java.util.Map[String, DirEntry]) = {
152+
@volatile lazy val (root, allDirs): (DirEntry, collection.Map[String, DirEntry]) = {
153153
val root = new DirEntry("/", null)
154-
val dirs = new java.util.HashMap[String, DirEntry]; dirs.put("/", root)
154+
val dirs = mutable.HashMap[String, DirEntry]("/" -> root)
155155
val zipFile = openZipFile()
156156
val entries = zipFile.entries()
157157

@@ -199,7 +199,7 @@ final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) {
199199
final class ManifestResources(val url: URL) extends ZipArchive(null) {
200200
def iterator(): Iterator[AbstractFile] = {
201201
val root = new DirEntry("/", null)
202-
val dirs = new java.util.HashMap[String, DirEntry]; dirs.put("/", root)
202+
val dirs = new mutable.HashMap[String, DirEntry]; dirs.put("/", root)
203203
val manifest = new Manifest(input)
204204
val iter = manifest.getEntries().keySet().iterator().asScala.filter(_.endsWith(".class")).map(new ZipEntry(_))
205205

0 commit comments

Comments
 (0)