Skip to content

Commit 06875f8

Browse files
authored
Merge pull request scala#7109 from retronym/topic/misc-aug
A pocketful of micro optimizations
2 parents 9cbe8b1 + 0586e02 commit 06875f8

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

src/compiler/scala/tools/nsc/transform/Erasure.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,9 @@ abstract class Erasure extends InfoTransform
825825
case Ident(_) | Select(_, _) =>
826826
if (tree1.symbol.isOverloaded) {
827827
val first = tree1.symbol.alternatives.head
828+
val firstTpe = first.tpe
828829
val sym1 = tree1.symbol.filter {
829-
alt => alt == first || !(first.tpe looselyMatches alt.tpe)
830+
alt => alt == first || !(firstTpe looselyMatches alt.tpe)
830831
}
831832
if (tree.symbol ne sym1) {
832833
tree1 setSymbol sym1 setType sym1.tpe

src/reflect/scala/reflect/internal/Definitions.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,14 +902,19 @@ trait Definitions extends api.StandardDefinitions {
902902
}
903903
}
904904
}
905+
def isVolatileTypeRef(tr: TypeRef) = {
906+
val dealised = tr.dealias
907+
if (dealised ne tr) isVolatile(dealised)
908+
else if (tr.sym.isAbstractType) isVolatileAbstractType
909+
else false
910+
}
905911

906912
tp match {
907913
case ThisType(_) => false
908914
case SingleType(_, sym) => isVolatile(tp.underlying) && (sym.hasVolatileType || !sym.isStable)
909915
case NullaryMethodType(restpe) => isVolatile(restpe)
910916
case PolyType(_, restpe) => isVolatile(restpe)
911-
case TypeRef(_, _, _) if tp ne tp.dealias => isVolatile(tp.dealias)
912-
case TypeRef(_, sym, _) if sym.isAbstractType => isVolatileAbstractType
917+
case tr: TypeRef => isVolatileTypeRef(tr)
913918
case RefinedType(_, _) => isVolatileRefinedType
914919
case TypeVar(origin, _) => isVolatile(origin)
915920
case _: SimpleTypeProxy => isVolatile(tp.underlying)

src/reflect/scala/reflect/internal/Names.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ trait Names extends api.Names {
191191
// compile loses track of this fact.
192192

193193
/** Index into name table */
194-
def start: Int = index
194+
final def start: Int = index
195195

196196
/** The next name in the same hash bucket. */
197197
def next: Name with ThisNameType

src/reflect/scala/reflect/internal/Scopes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,12 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
312312
var e: ScopeEntry = null
313313
if (hashtable ne null) {
314314
e = hashtable(name.start & HASHMASK)
315-
while ((e ne null) && e.sym.name != name) {
315+
while ((e ne null) && (e.sym.name ne name)) {
316316
e = e.tail
317317
}
318318
} else {
319319
e = elems
320-
while ((e ne null) && e.sym.name != name) {
320+
while ((e ne null) && (e.sym.name ne name)) {
321321
e = e.next
322322
}
323323
}

src/reflect/scala/reflect/internal/SymbolTable.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ abstract class SymbolTable extends macros.Universe
229229
}
230230

231231
final def phase_=(p: Phase): Unit = {
232-
//System.out.println("setting phase to " + p)
233-
assert((p ne null) && p != NoPhase, p)
234232
ph = p
235233
per = period(currentRunId, p.id)
236234
}

src/reflect/scala/reflect/internal/tpe/TypeMaps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ private[internal] trait TypeMaps {
130130
*/
131131
protected def noChangeToSymbols(origSyms: List[Symbol]): Boolean = {
132132
@tailrec def loop(syms: List[Symbol]): Boolean = syms match {
133-
case Nil => true
134133
case x :: xs => (x.info eq applyToSymbolInfo(x)) && loop(xs)
134+
case _ => true
135135
}
136136
loop(origSyms)
137137
}

0 commit comments

Comments
 (0)