Skip to content

Commit 2eb0303

Browse files
committed
Avoid some Some wrappers when accessing maps
1 parent b05a56c commit 2eb0303

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,12 @@ class TreePickler(pickler: TastyPickler) {
7171
case _ =>
7272
}
7373

74-
def registerDef(sym: Symbol): Unit = {
74+
def registerDef(sym: Symbol): Unit =
7575
symRefs(sym) = currentAddr
76-
forwardSymRefs.get(sym) match {
77-
case Some(refs) =>
78-
refs.foreach(fillRef(_, currentAddr, relative = false))
79-
forwardSymRefs -= sym
80-
case None =>
81-
}
82-
}
76+
val refs = forwardSymRefs.lookup(sym)
77+
if refs != null then
78+
refs.foreach(fillRef(_, currentAddr, relative = false))
79+
forwardSymRefs -= sym
8380

8481
def pickleName(name: Name): Unit = writeNat(nameIndex(name).index)
8582

@@ -88,17 +85,19 @@ class TreePickler(pickler: TastyPickler) {
8885
if (sig eq Signature.NotAMethod) name
8986
else SignedName(name.toTermName, sig, target.asTermName))
9087

91-
private def pickleSymRef(sym: Symbol)(using Context) = symRefs.get(sym) match {
92-
case Some(label) =>
93-
if (label != NoAddr) writeRef(label) else pickleForwardSymRef(sym)
94-
case None =>
88+
private def pickleSymRef(sym: Symbol)(using Context) =
89+
val label: Addr | Null = symRefs.lookup(sym)
90+
if label == null then
9591
// See pos/t1957.scala for an example where this can happen.
9692
// I believe it's a bug in typer: the type of an implicit argument refers
9793
// to a closure parameter outside the closure itself. TODO: track this down, so that we
9894
// can eliminate this case.
9995
report.log(i"pickling reference to as yet undefined $sym in ${sym.owner}", sym.srcPos)
10096
pickleForwardSymRef(sym)
101-
}
97+
else if label == NoAddr then
98+
pickleForwardSymRef(sym)
99+
else
100+
writeRef(label.uncheckedNN) // !!! Dotty problem: Not clear why nn or uncheckedNN is needed here
102101

103102
private def pickleForwardSymRef(sym: Symbol)(using Context) = {
104103
val ref = reserveRef(relative = false)
@@ -351,11 +350,10 @@ class TreePickler(pickler: TastyPickler) {
351350
throw ex
352351
if sym.is(Method) && sym.owner.isClass then
353352
profile.recordMethodSize(sym, currentAddr.index - addr.index, mdef.span)
354-
for
355-
docCtx <- ctx.docCtx
356-
comment <- docCtx.docstring(sym)
357-
do
358-
docStrings(mdef) = comment
353+
for docCtx <- ctx.docCtx do
354+
val comment = docCtx.docstrings.lookup(sym)
355+
if comment != null then
356+
docStrings(mdef) = comment
359357
}
360358

361359
def pickleParam(tree: Tree)(using Context): Unit = {

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,12 @@ object PatternMatcher {
664664
val refCount = varRefCount(plan)
665665
val LetPlan(topSym, _) = plan: @unchecked
666666

667-
def toDrop(sym: Symbol) = initializer.get(sym) match {
668-
case Some(rhs) =>
667+
def toDrop(sym: Symbol) =
668+
val rhs = initializer.lookup(sym)
669+
if rhs != null then
669670
isPatmatGenerated(sym) && refCount(sym) <= 1 && sym != topSym && isPureExpr(rhs)
670-
case none =>
671+
else
671672
false
672-
}
673673

674674
object Inliner extends PlanTransform {
675675
override val treeMap = new TreeMap {

0 commit comments

Comments
 (0)