summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@typesafe.com>2016-02-10 22:49:31 +0100
committerLukas Rytz <lukas.rytz@typesafe.com>2016-02-10 22:49:31 +0100
commitc0a6ab2376f08013c923de4e10bfdb925d0ee728 (patch)
treeb55df2bf9820c63ea4d130c44c56cb1573a954f9 /src
parentf9fdc5a7a8cce995b982b4a77c25bd9dba740ec4 (diff)
parentc3fcd4e5b0c8f03862ecf4f92fd43cf2fb8f5066 (diff)
downloadscala-c0a6ab2376f08013c923de4e10bfdb925d0ee728.tar.gz
scala-c0a6ab2376f08013c923de4e10bfdb925d0ee728.tar.bz2
scala-c0a6ab2376f08013c923de4e10bfdb925d0ee728.zip
Merge pull request #4954 from retronym/topic/fullname
Micro optimise Symbol#fullName
Diffstat (limited to 'src')
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index 11e740117d..3b9ee9048a 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -1256,8 +1256,9 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
/** These should be moved somewhere like JavaPlatform.
*/
def javaSimpleName: Name = addModuleSuffix(simpleName.dropLocal)
- def javaBinaryName: Name = addModuleSuffix(fullNameInternal('/'))
- def javaClassName: String = addModuleSuffix(fullNameInternal('.')).toString
+ def javaBinaryName: Name = name.newName(javaBinaryNameString)
+ def javaBinaryNameString: String = fullName('/', moduleSuffix)
+ def javaClassName: String = fullName('.', moduleSuffix)
/** The encoded full path name of this symbol, where outer names and inner names
* are separated by `separator` characters.
@@ -1265,18 +1266,29 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
* Never adds id.
* Drops package objects.
*/
- final def fullName(separator: Char): String = fullNameAsName(separator).toString
-
- /** Doesn't drop package objects, for those situations (e.g. classloading)
- * where the true path is needed.
- */
- private def fullNameInternal(separator: Char): Name = (
- if (isRoot || isRootPackage || this == NoSymbol) name
- else if (owner.isEffectiveRoot) name
- else effectiveOwner.enclClass.fullNameAsName(separator) append (separator, name)
- )
+ final def fullName(separator: Char): String = fullName(separator, "")
+
+ private def fullName(separator: Char, suffix: CharSequence): String = {
+ var b: java.lang.StringBuffer = null
+ def loop(size: Int, sym: Symbol): Unit = {
+ val symName = sym.name
+ val nSize = symName.length - (if (symName.endsWith(nme.LOCAL_SUFFIX_STRING)) 1 else 0)
+ if (sym.isRoot || sym.isRootPackage || sym == NoSymbol || sym.owner.isEffectiveRoot) {
+ val capacity = size + nSize
+ b = new java.lang.StringBuffer(capacity)
+ b.append(chrs, symName.start, nSize)
+ } else {
+ loop(size + nSize + 1, sym.effectiveOwner.enclClass)
+ b.append(separator)
+ b.append(chrs, symName.start, nSize)
+ }
+ }
+ loop(suffix.length(), this)
+ b.append(suffix)
+ b.toString
+ }
- def fullNameAsName(separator: Char): Name = fullNameInternal(separator).dropLocal
+ def fullNameAsName(separator: Char): Name = name.newName(fullName(separator, ""))
/** The encoded full path name of this symbol, where outer names and inner names
* are separated by periods.