Skip to content

Commit 842c90f

Browse files
committed
Inline extractors to avoid indirection to sym checks
1 parent eb4d2c8 commit 842c90f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ class StringInterpolatorOpt extends MiniPhase {
4444
/** Matches an s or raw string interpolator */
4545
private object SOrRawInterpolator {
4646
def unapply(tree: Tree)(implicit ctx: Context): Option[(List[Literal], List[Tree])] = {
47-
if (tree.symbol.eq(defn.StringContextRaw) || tree.symbol.eq(defn.StringContextS)) {
48-
tree match {
49-
case Apply(Select(Apply(StringContextApply(), List(Literals(strs))), _),
50-
List(SeqLiteral(elems, _))) if elems.length == strs.length - 1 =>
51-
Some(strs, elems)
52-
case _ => None
53-
}
54-
} else None
47+
tree match {
48+
case Apply(Select(Apply(StringContextApply(), List(Literals(strs))), _),
49+
List(SeqLiteral(elems, _))) if elems.length == strs.length - 1 =>
50+
Some(strs, elems)
51+
case _ => None
52+
}
5553
}
5654
}
5755

@@ -82,6 +80,12 @@ class StringInterpolatorOpt extends MiniPhase {
8280
}
8381

8482
override def transformApply(tree: Apply)(implicit ctx: Context): Tree = {
83+
val sym = tree.symbol
84+
if (sym.ne(defn.StringContextRaw) && sym.ne(defn.StringContextS)) tree
85+
else transformInterpolator(tree)
86+
}
87+
88+
private def transformInterpolator(tree: Tree)(implicit ctx: Context): Tree = {
8589
tree match {
8690
case StringContextIntrinsic(strs: List[Literal], elems: List[Tree]) =>
8791
val stri = strs.iterator

0 commit comments

Comments
 (0)