Skip to content

Commit af7bde7

Browse files
Merge pull request #4267 from dotty-staging/small-performance-enhancements
Small performance enhancements
2 parents 0e31883 + 39de3a5 commit af7bde7

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ class InterceptedMethods extends MiniPhase {
4444

4545
override def phaseName: String = InterceptedMethods.name
4646

47-
private[this] var primitiveGetClassMethods: Set[Symbol] = _
48-
49-
/** perform context-dependant initialization */
50-
override def prepareForUnit(tree: Tree)(implicit ctx: Context) = {
51-
primitiveGetClassMethods = Set[Symbol]() ++ defn.ScalaValueClasses().map(x => x.requiredMethod(nme.getClass_))
52-
ctx
53-
}
54-
5547
// this should be removed if we have guarantee that ## will get Apply node
5648
override def transformSelect(tree: tpd.Select)(implicit ctx: Context): Tree = {
5749
if (tree.symbol.isTerm && (defn.Any_## eq tree.symbol.asTerm)) {
@@ -105,7 +97,7 @@ class InterceptedMethods extends MiniPhase {
10597
List(qual, typer.resolveClassTag(tree.pos, qual.tpe.widen))))
10698
}*/
10799
*/
108-
case t if primitiveGetClassMethods.contains(t) =>
100+
case t if t.name == nme.getClass_ && defn.ScalaValueClasses().contains(t.owner) =>
109101
// if we got here then we're trying to send a primitive getClass method to either
110102
// a) an Any, in which cage Object_getClass works because Any erases to object. Or
111103
//

compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,19 @@ class Simplify extends MiniPhase with IdentityDenotTransformer {
7979
var fuel: Int = -1
8080

8181
override def prepareForUnit(tree: Tree)(implicit ctx: Context) = {
82-
SeqFactoryClass = ctx.requiredClass("scala.collection.generic.SeqFactory")
83-
CommutativePrimitiveOperations = Set(defn.Boolean_&&, defn.Boolean_||, defn.Int_+, defn.Int_*, defn.Long_+, defn.Long_*)
84-
85-
val maxFuel = ctx.settings.YoptFuel.value
86-
if (fuel < 0 && maxFuel > 0) // Both defaults are at -1
87-
fuel = maxFuel
88-
89-
optimisations = {
90-
val o = if (ctx.erasedTypes) afterErasure else beforeErasure
91-
val p = ctx.settings.YoptPhases.value
92-
if (p.isEmpty) o else o.filter(x => p.contains(x.name))
82+
if (ctx.settings.optimise.value) {
83+
SeqFactoryClass = ctx.requiredClass("scala.collection.generic.SeqFactory")
84+
CommutativePrimitiveOperations = Set(defn.Boolean_&&, defn.Boolean_||, defn.Int_+, defn.Int_*, defn.Long_+, defn.Long_*)
85+
86+
val maxFuel = ctx.settings.YoptFuel.value
87+
if (fuel < 0 && maxFuel > 0) // Both defaults are at -1
88+
fuel = maxFuel
89+
90+
optimisations = {
91+
val o = if (ctx.erasedTypes) afterErasure else beforeErasure
92+
val p = ctx.settings.YoptPhases.value
93+
if (p.isEmpty) o else o.filter(x => p.contains(x.name))
94+
}
9395
}
9496

9597
ctx

0 commit comments

Comments
 (0)