Skip to content

Commit 57c0a43

Browse files
committed
Convert some mutable.HashMaps to util.HashMaps
1 parent 29ddc17 commit 57c0a43

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
108108
private def mergeClassesAndSources(entries: scala.collection.Seq[ClassRepresentation]): Seq[ClassRepresentation] = {
109109
// based on the implementation from MergedClassPath
110110
var count = 0
111-
val indices = new collection.mutable.HashMap[String, Int]()
111+
val indices = util.HashMap[String, Int]()
112112
val mergedEntries = new ArrayBuffer[ClassRepresentation](entries.size)
113113
for {
114114
entry <- entries

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
22
* Copyright (c) 2014 Contributor. All rights reserved.
33
*/
4-
package dotty.tools.dotc.classpath
4+
package dotty.tools.dotc
5+
package classpath
56

67
import java.io.File
78
import java.net.URL
@@ -12,6 +13,7 @@ import scala.annotation.tailrec
1213
import dotty.tools.io.{AbstractFile, ClassPath, ClassRepresentation, FileZipArchive, ManifestResources}
1314
import dotty.tools.dotc.core.Contexts._
1415
import FileUtils._
16+
import util._
1517

1618
/**
1719
* A trait providing an optional cache for classpath entries obtained from zip and jar files.
@@ -89,8 +91,8 @@ object ZipAndJarClassPathFactory extends ZipAndJarFileLookupFactory {
8991
* when we need subpackages of a given package or its classes, we traverse once and cache only packages.
9092
* Classes for given package can be then easily loaded when they are needed.
9193
*/
92-
private lazy val cachedPackages: collection.mutable.HashMap[String, PackageFileInfo] = {
93-
val packages = collection.mutable.HashMap[String, PackageFileInfo]()
94+
private lazy val cachedPackages: util.HashMap[String, PackageFileInfo] = {
95+
val packages = util.HashMap[String, PackageFileInfo]()
9496

9597
def getSubpackages(dir: AbstractFile): List[AbstractFile] =
9698
(for (file <- dir if file.isPackage) yield file).toList
@@ -102,7 +104,7 @@ object ZipAndJarClassPathFactory extends ZipAndJarFileLookupFactory {
102104
case pkgFile :: remainingFiles =>
103105
val subpackages = getSubpackages(pkgFile)
104106
val fullPkgName = packagePrefix + pkgFile.name
105-
packages.put(fullPkgName, PackageFileInfo(pkgFile, subpackages))
107+
packages(fullPkgName) = PackageFileInfo(pkgFile, subpackages)
106108
val newPackagePrefix = fullPkgName + "."
107109
subpackagesQueue.enqueue(PackageInfo(newPackagePrefix, subpackages))
108110
traverse(packagePrefix, remainingFiles, subpackagesQueue)
@@ -113,7 +115,7 @@ object ZipAndJarClassPathFactory extends ZipAndJarFileLookupFactory {
113115
}
114116

115117
val subpackages = getSubpackages(file)
116-
packages.put(ClassPath.RootPackage, PackageFileInfo(file, subpackages))
118+
packages(ClassPath.RootPackage) = PackageFileInfo(file, subpackages)
117119
traverse(ClassPath.RootPackage, subpackages, collection.mutable.Queue())
118120
packages
119121
}

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4321,7 +4321,7 @@ object Types {
43214321
def underlying(using Context): Type = bound
43224322

43234323
private var myReduced: Type = null
4324-
private var reductionContext: mutable.Map[Type, Type] = null
4324+
private var reductionContext: util.MutableMap[Type, Type] = null
43254325

43264326
override def tryNormalize(using Context): Type = reduced.normalized
43274327

@@ -4340,7 +4340,7 @@ object Types {
43404340
}
43414341

43424342
def updateReductionContext(footprint: collection.Set[Type]): Unit =
4343-
reductionContext = new mutable.HashMap
4343+
reductionContext = util.HashMap()
43444344
for (tp <- footprint)
43454345
reductionContext(tp) = contextInfo(tp)
43464346
typr.println(i"footprint for $this $hashCode: ${footprint.toList.map(x => (x, contextInfo(x)))}%, %")

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -732,15 +732,13 @@ class ClassfileParser(
732732
classTranslation.flags(jflags),
733733
getScope(jflags))
734734

735-
for (entry <- innerClasses.values) {
735+
for entry <- innerClasses.valuesIterator do
736736
// create a new class member for immediate inner classes
737-
if (entry.outerName == currentClassName) {
737+
if entry.outerName == currentClassName then
738738
val file = ctx.platform.classPath.findClassFile(entry.externalName.toString) getOrElse {
739739
throw new AssertionError(entry.externalName)
740740
}
741741
enterClassAndModule(entry, file, entry.jflags)
742-
}
743-
}
744742
}
745743

746744
// Nothing$ and Null$ were incorrectly emitted with a Scala attribute
@@ -937,14 +935,14 @@ class ClassfileParser(
937935
s"$originalName in $outerName($externalName)"
938936
}
939937

940-
object innerClasses extends scala.collection.mutable.HashMap[Name, InnerClassEntry] {
938+
object innerClasses extends util.HashMap[Name, InnerClassEntry] {
941939
/** Return the Symbol of the top level class enclosing `name`,
942940
* or 'name's symbol if no entry found for `name`.
943941
*/
944942
def topLevelClass(name: Name)(using Context): Symbol = {
945-
val tlName = if (isDefinedAt(name)) {
943+
val tlName = if (contains(name)) {
946944
var entry = this(name)
947-
while (isDefinedAt(entry.outerName))
945+
while (contains(entry.outerName))
948946
entry = this(entry.outerName)
949947
entry.outerName
950948
}

compiler/src/dotty/tools/dotc/util/GenericHashMap.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ abstract class GenericHashMap[Key, Value]
177177
def keysIterator: Iterator[Key] = new EntryIterator:
178178
def entry(idx: Int) = keyAt(idx)
179179

180+
def valuesIterator: Iterator[Value] = new EntryIterator:
181+
def entry(idx: Int) = valueAt(idx)
182+
180183
override def toString: String =
181184
iterator.map((k, v) => s"$k -> $v").mkString("HashMap(", ", ", ")")
182185

0 commit comments

Comments
 (0)