Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another grab bag of compiler optimizations #3449

Merged
merged 4 commits into from Feb 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
Expand Up @@ -46,8 +46,10 @@ abstract class GenICode extends SubComponent {
var unit: CompilationUnit = NoCompilationUnit

override def run() {
scalaPrimitives.init()
classes.clear()
if (!settings.isBCodeActive) {
scalaPrimitives.init()
classes.clear()
}
super.run()
}

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/scala/tools/nsc/backend/icode/Members.scala
Expand Up @@ -21,16 +21,16 @@ trait Members {

import global._

object NoCode extends Code(null, "NoCode") {
object NoCode extends Code(null, TermName("NoCode")) {
override def blocksList: List[BasicBlock] = Nil
}

/**
* This class represents the intermediate code of a method or
* other multi-block piece of code, like exception handlers.
*/
class Code(method: IMethod, name: String) {
def this(method: IMethod) = this(method, method.symbol.decodedName.toString.intern)
class Code(method: IMethod, name: Name) {
def this(method: IMethod) = this(method, method.symbol.name)
/** The set of all blocks */
val blocks = mutable.ListBuffer[BasicBlock]()

Expand Down Expand Up @@ -82,7 +82,7 @@ trait Members {
}

/** This methods returns a string representation of the ICode */
override def toString = "ICode '" + name + "'"
override def toString = "ICode '" + name.decoded + "'"

/* Compute a unique new label */
def nextLabel: Int = {
Expand Down
17 changes: 14 additions & 3 deletions src/compiler/scala/tools/nsc/transform/Erasure.scala
Expand Up @@ -92,11 +92,22 @@ abstract class Erasure extends AddInterfaces
// more rigorous way up front rather than catching it after the fact,
// but that will be more involved.
private def dotCleanup(sig: String): String = {
// OPT 50% of time in generic signatures (~1% of compile time) was in this method, hence the imperative rewrite.
var last: Char = '\u0000'
sig map {
case '.' if last != '>' => last = '.' ; '$'
case ch => last = ch ; ch
var i = 0
val len = sig.length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good spot, I guess I meant to use it in the while.

val copy: Array[Char] = sig.toCharArray
var changed = false
while (i < sig.length) {
val ch = copy(i)
if (ch == '.' && last != '>') {
copy(i) = '$'
changed = true
}
last = ch
i += 1
}
if (changed) new String(copy) else sig
}

/** This object is only used for sanity testing when -check:genjvm is set.
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/scala/tools/nsc/transform/UnCurry.scala
Expand Up @@ -105,12 +105,11 @@ abstract class UnCurry extends InfoTransform
*/
def isByNameRef(tree: Tree) = (
tree.isTerm
&& !byNameArgs(tree)
&& (tree.symbol ne null)
&& (isByName(tree.symbol))
&& !byNameArgs(tree)
)


// ------- Handling non-local returns -------------------------------------------------

/** The type of a non-local return expression with given argument type */
Expand Down
35 changes: 25 additions & 10 deletions src/reflect/scala/reflect/internal/Names.scala
Expand Up @@ -345,6 +345,13 @@ trait Names extends api.Names {
i += 1
i == prefix.length
}
final def startsWith(prefix: String, start: Int): Boolean = {
var i = 0
while (i < prefix.length && start + i < len &&
chrs(index + start + i) == prefix.charAt(i))
i += 1
i == prefix.length
}

/** Does this name end with suffix? */
final def endsWith(suffix: Name): Boolean = endsWith(suffix, len)
Expand All @@ -357,6 +364,13 @@ trait Names extends api.Names {
i += 1
i > suffix.length
}
final def endsWith(suffix: String, end: Int): Boolean = {
var i = 1
while (i <= suffix.length && i <= end &&
chrs(index + end - i) == suffix.charAt(suffix.length - i))
i += 1
i > suffix.length
}

final def containsName(subname: String): Boolean = containsName(newTermName(subname))
final def containsName(subname: Name): Boolean = {
Expand All @@ -382,9 +396,9 @@ trait Names extends api.Names {
final def startChar: Char = this charAt 0
final def endChar: Char = this charAt len - 1
final def startsWith(char: Char): Boolean = len > 0 && startChar == char
final def startsWith(name: String): Boolean = startsWith(newTermName(name))
final def startsWith(name: String): Boolean = startsWith(name, 0)
final def endsWith(char: Char): Boolean = len > 0 && endChar == char
final def endsWith(name: String): Boolean = endsWith(newTermName(name))
final def endsWith(name: String): Boolean = endsWith(name, len)

/** Rewrite the confusing failure indication via result == length to
* the normal failure indication via result == -1.
Expand Down Expand Up @@ -443,9 +457,10 @@ trait Names extends api.Names {
}

/** TODO - find some efficiency. */
def append(ch: Char) = newName("" + this + ch)
def append(suffix: String) = newName("" + this + suffix)
def append(suffix: Name) = newName("" + this + suffix)
def append(ch: Char) = newName(toString + ch)
def append(suffix: String) = newName(toString + suffix)
def append(suffix: Name) = newName(toString + suffix)
def append(separator: Char, suffix: Name) = newName(toString + separator + suffix)
def prepend(prefix: String) = newName("" + prefix + this)

def decodedName: ThisNameType = newName(decode)
Expand All @@ -463,7 +478,7 @@ trait Names extends api.Names {
*/
final class NameOps[T <: Name](name: T) {
import NameTransformer._
def stripSuffix(suffix: String): T = stripSuffix(suffix: TermName)
def stripSuffix(suffix: String): T = if (name endsWith suffix) dropRight(suffix.length) else name // OPT avoid creating a Name with `suffix`
def stripSuffix(suffix: Name): T = if (name endsWith suffix) dropRight(suffix.length) else name
def take(n: Int): T = name.subName(0, n).asInstanceOf[T]
def drop(n: Int): T = name.subName(n, name.length).asInstanceOf[T]
Expand Down Expand Up @@ -500,21 +515,21 @@ trait Names extends api.Names {
/** TermName_S and TypeName_S have fields containing the string version of the name.
* TermName_R and TypeName_R recreate it each time toString is called.
*/
private class TermName_S(index0: Int, len0: Int, hash: Int, override val toString: String) extends TermName(index0, len0, hash) {
private final class TermName_S(index0: Int, len0: Int, hash: Int, override val toString: String) extends TermName(index0, len0, hash) {
protected def createCompanionName(h: Int): TypeName = new TypeName_S(index, len, h, toString)
override def newName(str: String): TermName = newTermNameCached(str)
}
private class TypeName_S(index0: Int, len0: Int, hash: Int, override val toString: String) extends TypeName(index0, len0, hash) {
private final class TypeName_S(index0: Int, len0: Int, hash: Int, override val toString: String) extends TypeName(index0, len0, hash) {
protected def createCompanionName(h: Int): TermName = new TermName_S(index, len, h, toString)
override def newName(str: String): TypeName = newTypeNameCached(str)
}

private class TermName_R(index0: Int, len0: Int, hash: Int) extends TermName(index0, len0, hash) {
private final class TermName_R(index0: Int, len0: Int, hash: Int) extends TermName(index0, len0, hash) {
protected def createCompanionName(h: Int): TypeName = new TypeName_R(index, len, h)
override def toString = new String(chrs, index, len)
}

private class TypeName_R(index0: Int, len0: Int, hash: Int) extends TypeName(index0, len0, hash) {
private final class TypeName_R(index0: Int, len0: Int, hash: Int) extends TypeName(index0, len0, hash) {
protected def createCompanionName(h: Int): TermName = new TermName_R(index, len, h)
override def toString = new String(chrs, index, len)
}
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Symbols.scala
Expand Up @@ -1102,7 +1102,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
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) append name
else effectiveOwner.enclClass.fullNameAsName(separator) append (separator, name)
)

def fullNameAsName(separator: Char): Name = fullNameInternal(separator).dropLocal
Expand Down