Skip to content

Commit 4fb0b75

Browse files
committed
Improve performance by avoiding needless Name => String => Name conversion
1 parent e0cbd12 commit 4fb0b75

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/main/scala/scala/async/internal/AnfTransform.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ private[async] trait AnfTransform {
154154
}
155155
}
156156

157-
def defineVar(prefix: String, tp: Type, pos: Position): ValDef = {
157+
def defineVar(prefix: TermName, tp: Type, pos: Position): ValDef = {
158158
val sym = api.currentOwner.newTermSymbol(name.fresh(prefix), pos, MUTABLE | SYNTHETIC).setInfo(uncheckedBounds(tp))
159159
valDef(sym, mkZero(uncheckedBounds(tp))).setType(NoType).setPos(pos)
160160
}
161161
}
162162

163-
def defineVal(prefix: String, lhs: Tree, pos: Position): ValDef = {
163+
def defineVal(prefix: TermName, lhs: Tree, pos: Position): ValDef = {
164164
val sym = api.currentOwner.newTermSymbol(name.fresh(prefix), pos, SYNTHETIC).setInfo(uncheckedBounds(lhs.tpe))
165165
internal.valDef(sym, internal.changeOwner(lhs, api.currentOwner, sym)).setType(NoType).setPos(pos)
166166
}

src/main/scala/scala/async/internal/TransformUtils.scala

+10-10
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ private[async] trait TransformUtils {
3232
}
3333

3434
object name {
35-
def matchRes = maybeFresh(baseNames.matchRes)
36-
def ifRes = maybeFresh(baseNames.ifRes)
37-
def bindSuffix = maybeFresh(baseNames.bindSuffix)
38-
def completed = maybeFresh(baseNames.completed)
35+
val matchRes = newTermName(baseNames.matchRes)
36+
val ifRes = newTermName(baseNames.ifRes)
37+
def bindSuffix = baseNames.bindSuffix
38+
def completed = baseNames.completed
3939

4040
val state = maybeFresh(baseNames.state)
4141
val result = baseNames.result
4242
val execContext = maybeFresh(baseNames.execContext)
4343
val tr = maybeFresh(baseNames.tr)
4444
val t = maybeFresh(baseNames.t)
4545

46-
val await = "await"
46+
val await = newTermName("await")
4747
val resume = newTermName("resume")
4848
val apply = newTermName("apply")
4949
val stateMachine = newTermName(fresh("stateMachine"))
@@ -162,10 +162,10 @@ private[async] trait TransformUtils {
162162
(i, j) => util.Try(byNamess(i)(j)).getOrElse(false)
163163
}
164164
}
165-
private def argName(fun: Tree): ((Int, Int) => String) = {
165+
private def argName(fun: Tree): ((Int, Int) => TermName) = {
166166
val paramss = fun.tpe.paramss
167-
val namess = paramss.map(_.map(_.name.toString))
168-
(i, j) => util.Try(namess(i)(j)).getOrElse(s"arg_${i}_${j}")
167+
val namess = paramss.map(_.map(_.name.toTermName))
168+
(i, j) => util.Try(namess(i)(j)).getOrElse(TermName(s"arg_${i}_${j}"))
169169
}
170170

171171
object defn {
@@ -246,7 +246,7 @@ private[async] trait TransformUtils {
246246
}
247247
}
248248

249-
case class Arg(expr: Tree, isByName: Boolean, argName: String)
249+
case class Arg(expr: Tree, isByName: Boolean, argName: TermName)
250250

251251
/**
252252
* Transform a list of argument lists, producing the transformed lists, and lists of auxillary
@@ -261,7 +261,7 @@ private[async] trait TransformUtils {
261261
*/
262262
def mapArgumentss[A](fun: Tree, argss: List[List[Tree]])(f: Arg => (A, Tree)): (List[List[A]], List[List[Tree]]) = {
263263
val isByNamess: (Int, Int) => Boolean = isByName(fun)
264-
val argNamess: (Int, Int) => String = argName(fun)
264+
val argNamess: (Int, Int) => TermName = argName(fun)
265265
argss.zipWithIndex.map { case (args, i) =>
266266
mapArguments[A](args) {
267267
(tree, j) => f(Arg(tree, isByNamess(i, j), argNamess(i, j)))

0 commit comments

Comments
 (0)