From d190139373ef265b62f6ca499a1bc360b5fc0e8a Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Sat, 17 May 2014 07:58:34 +0200 Subject: Re-use the exsiting range of the name table when using subName. The sub-name can just point to a smaller range of the array. --- src/reflect/scala/reflect/internal/Names.scala | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/reflect/scala/reflect/internal/Names.scala b/src/reflect/scala/reflect/internal/Names.scala index 05c060e81f..b50f324074 100644 --- a/src/reflect/scala/reflect/internal/Names.scala +++ b/src/reflect/scala/reflect/internal/Names.scala @@ -107,12 +107,18 @@ trait Names extends api.Names { // The logic order here is future-proofing against the possibility // that name.toString will become an eager val, in which case the call // to enterChars cannot follow the construction of the TermName. - val ncStart = nc - enterChars(cs, offset, len) + var startIndex = 0 + if (cs == chrs) { + // Optimize for subName, the new name is already stored in chrs + startIndex = offset + } else { + startIndex = nc + enterChars(cs, offset, len) + } val next = termHashtable(h) val termName = - if (cachedString ne null) new TermName_S(ncStart, len, next, cachedString) - else new TermName_R(ncStart, len, next) + if (cachedString ne null) new TermName_S(startIndex, len, next, cachedString) + else new TermName_R(startIndex, len, next) // Add the new termName to the hashtable only after it's been fully constructed termHashtable(h) = termName termName -- cgit v1.2.3