Skip to content

Commit a68ba13

Browse files
retronymnicolasstucki
authored andcommitted
Optimize use of hash maps in makeLocal in the back end
- Use an AnyRefMap rather than a general hash map - Avoid a map lookup in an assertion Port of scala#6070
1 parent 2d90208 commit a68ba13

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
350350
*/
351351
object locals {
352352

353-
private val slots = mutable.Map.empty[Symbol, Local] // (local-or-param-sym -> Local(BType, name, idx, isSynth))
353+
private val slots = mutable.AnyRefMap.empty[Symbol, Local] // (local-or-param-sym -> Local(BType, name, idx, isSynth))
354354

355355
private var nxtIdx = -1 // next available index for local-var
356356

@@ -383,10 +383,11 @@ trait BCodeSkelBuilder extends BCodeHelpers {
383383
}
384384

385385
private def makeLocal(sym: Symbol, tk: BType): Local = {
386-
assert(!slots.contains(sym), "attempt to create duplicate local var.")
387386
assert(nxtIdx != -1, "not a valid start index")
388387
val loc = Local(tk, sym.javaSimpleName.toString, nxtIdx, sym.isSynthetic)
389-
slots += (sym -> loc)
388+
val existing = slots.put(sym, loc)
389+
if (existing.isDefined)
390+
error(sym.pos, "attempt to create duplicate local var.")
390391
assert(tk.size > 0, "makeLocal called for a symbol whose type is Unit.")
391392
nxtIdx += tk.size
392393
loc

0 commit comments

Comments
 (0)