Skip to content

Commit 08050d7

Browse files
committed
Memoize toSimpleName
toSimpleName is called a lot from the backend, so it makes sense to memoize it. It would be even better to communicate with the backend using strings, because then we would not have to enter all these simple names in the name table.
1 parent 3cfc36f commit 08050d7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/src/dotty/tools/dotc/core/Names.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,12 @@ object Names {
339339

340340
def isSimple = false
341341
def asSimpleName = throw new UnsupportedOperationException(s"$debugString is not a simple name")
342-
def toSimpleName = termName(toString)
342+
343+
private var simpleName: SimpleTermName = null
344+
def toSimpleName = {
345+
if (simpleName == null) simpleName = termName(toString)
346+
simpleName
347+
}
343348

344349
def rewrite(f: PartialFunction[Name, Name]): ThisName =
345350
if (f.isDefinedAt(this)) likeSpaced(f(this))

0 commit comments

Comments
 (0)