diff options
author | Paul Phillips <paulp@improving.org> | 2011-12-24 23:13:58 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-12-25 00:53:00 -0800 |
commit | a31e4f8a75f9162ab2f0c8d3bec42675b29fefb5 (patch) | |
tree | 2d7dc5d7cb35b3ea5d667cdc15edcaaab2a73f06 /src/compiler/scala/reflect/internal/Symbols.scala | |
parent | 8834d3c191e37dfa31ae11605596ce2b641ea083 (diff) | |
download | scala-a31e4f8a75f9162ab2f0c8d3bec42675b29fefb5.tar.gz scala-a31e4f8a75f9162ab2f0c8d3bec42675b29fefb5.tar.bz2 scala-a31e4f8a75f9162ab2f0c8d3bec42675b29fefb5.zip |
Optimizing at the Name/String boundary.
Working on reducing the now significant amount of both
garbage and retained but duplicated Strings taking place
as Names become Strings and vice versa. Long way to go.
Diffstat (limited to 'src/compiler/scala/reflect/internal/Symbols.scala')
-rw-r--r-- | src/compiler/scala/reflect/internal/Symbols.scala | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index bc0c81a54b..0c57f0c43a 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -756,7 +756,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** If this symbol has an expanded name, its original name, otherwise its name itself. * @see expandName */ - def originalName = nme.originalName(name) + def originalName: Name = nme.originalName(name) /** The name of the symbol before decoding, e.g. `\$eq\$eq` instead of `==`. */ @@ -764,20 +764,28 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** The decoded name of the symbol, e.g. `==` instead of `\$eq\$eq`. */ - def decodedName: String = stripNameString(NameTransformer.decode(encodedName)) + def decodedName: String = nme.dropLocalSuffix(name).decode - /** Either "$" or "" depending on whether this is a module class. - */ + private def addModuleSuffix(n: Name): Name = + if (needsModuleSuffix) n append nme.MODULE_SUFFIX_STRING else n + def moduleSuffix: String = ( - if (hasModuleFlag && !isMethod && !isImplClass && !isJavaDefined) nme.MODULE_SUFFIX_STRING + if (needsModuleSuffix) nme.MODULE_SUFFIX_STRING else "" ) - + /** Whether this symbol needs nme.MODULE_SUFFIX_STRING (aka $) appended on the java platform. + */ + def needsModuleSuffix = ( + hasModuleFlag + && !isMethod + && !isImplClass + && !isJavaDefined + ) /** These should be moved somewhere like JavaPlatform. */ - def javaSimpleName = ("" + simpleName).trim + moduleSuffix - def javaBinaryName = fullNameInternal('/') + moduleSuffix - def javaClassName = fullNameInternal('.') + moduleSuffix + def javaSimpleName: String = addModuleSuffix(nme.dropLocalSuffix(simpleName)).toString + def javaBinaryName: String = addModuleSuffix(fullNameInternal('/')).toString + def javaClassName: String = addModuleSuffix(fullNameInternal('.')).toString /** The encoded full path name of this symbol, where outer names and inner names * are separated by `separator` characters. @@ -785,23 +793,17 @@ trait Symbols extends api.Symbols { self: SymbolTable => * Never adds id. * Drops package objects. */ - final def fullName(separator: Char): String = stripNameString(fullNameInternal(separator)) + final def fullName(separator: Char): String = nme.dropLocalSuffix(fullNameInternal(separator)).toString /** Doesn't drop package objects, for those situations (e.g. classloading) * where the true path is needed. */ - private def fullNameInternal(separator: Char): String = ( - if (isRoot || isRootPackage || this == NoSymbol) this.toString - else if (owner.isEffectiveRoot) encodedName - else effectiveOwner.enclClass.fullName(separator) + separator + encodedName + private def fullNameInternal(separator: Char): Name = ( + if (isRoot || isRootPackage || this == NoSymbol) name + else if (owner.isEffectiveRoot) name + else effectiveOwner.enclClass.fullName(separator) append separator append name ) - /** Strip package objects and any local suffix. - */ - private def stripNameString(s: String) = - if (settings.debug.value) s - else s stripSuffix nme.LOCAL_SUFFIX_STRING - /** The encoded full path name of this symbol, where outer names and inner names * are separated by periods. */ @@ -1702,7 +1704,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => */ final def getter(base: Symbol): Symbol = base.info.decl(getterName) filter (_.hasAccessorFlag) - def getterName = ( + def getterName: Name = ( if (isSetter) nme.setterToGetter(name) else if (nme.isLocalName(name)) nme.localToGetter(name) else name @@ -1800,7 +1802,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => // ------ toString ------------------------------------------------------------------- /** A tag which (in the ideal case) uniquely identifies class symbols */ - final def tag = fullName.## + final def tag: Int = fullName.## /** The simple name of this Symbol */ final def simpleName: Name = name @@ -1810,7 +1812,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => * (the initial Name) before falling back on id, which varies depending * on exactly when a symbol is loaded. */ - final def sealedSortName = initName + "#" + id + final def sealedSortName: String = initName + "#" + id /** String representation of symbol's definition key word */ final def keyString: String = @@ -1878,7 +1880,10 @@ trait Symbols extends api.Symbols { self: SymbolTable => * E.g. $eq => =. * If settings.uniqid, adds id. */ - def nameString = decodedName + idString + def nameString: String = ( + if (settings.uniqid.value) decodedName + "#" + id + else "" + decodedName + ) /** If settings.uniqid is set, the symbol's id, else "" */ final def idString = if (settings.uniqid.value) "#"+id else "" @@ -1886,14 +1891,14 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** String representation, including symbol's kind e.g., "class Foo", "method Bar". * If hasMeaninglessName is true, uses the owner's name to disambiguate identity. */ - override def toString = compose( + override def toString: String = compose( kindString, if (hasMeaninglessName) owner.decodedName + idString else nameString ) /** String representation of location. */ - def ownsString = { + def ownsString: String = { val owns = effectiveOwner if (owns.isClass && !owns.isEmptyPrefix) "" + owns else "" } @@ -1901,12 +1906,12 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** String representation of location, plus a preposition. Doesn't do much, * for backward compatibility reasons. */ - def locationString = ownsString match { + def locationString: String = ownsString match { case "" => "" case s => " in " + s } - def fullLocationString = toString + locationString - def signatureString = if (hasRawInfo) infoString(rawInfo) else "<_>" + def fullLocationString: String = toString + locationString + def signatureString: String = if (hasRawInfo) infoString(rawInfo) else "<_>" /** String representation of symbol's definition following its name */ final def infoString(tp: Type): String = { |