Skip to content

Commit

Permalink
Merge pull request #25 from dotty-staging/port-#6070
Browse files Browse the repository at this point in the history
Optimize use of hash maps in makeLocal in the back end
  • Loading branch information
nicolasstucki authored Sep 20, 2017
2 parents 2d90208 + a68ba13 commit 83b68e5
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
*/
object locals {

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

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

Expand Down Expand Up @@ -383,10 +383,11 @@ trait BCodeSkelBuilder extends BCodeHelpers {
}

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

0 comments on commit 83b68e5

Please sign in to comment.