Skip to content

Commit d9a429c

Browse files
committed
Make TyperState#test an inline method
Avoids the closure creation and megamorphic call. Note: The method is probably too large to be inlined automatically by the JVM.
1 parent dc08e7f commit d9a429c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

compiler/src/dotty/tools/dotc/core/TyperState.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,23 @@ class TyperState(previous: TyperState /* | Null */) extends DotClass with Showab
8686
def uncommittedAncestor: TyperState =
8787
if (isCommitted) previous.uncommittedAncestor else this
8888

89-
private var testReporter: StoreReporter = null
89+
private var myTestReporter: StoreReporter = null
90+
91+
def testReporter =
92+
if (myTestReporter == null) new StoreReporter(reporter)
93+
else {
94+
myTestReporter.reset()
95+
myTestReporter
96+
}
9097

9198
/** Test using `op`, restoring typerState to previous state afterwards */
92-
def test(op: => Boolean): Boolean = {
99+
@inline def test(op: => Boolean): Boolean = {
93100
val savedReporter = myReporter
94101
val savedConstraint = myConstraint
95102
val savedCommittable = myIsCommittable
96103
val savedCommitted = isCommitted
97104
myIsCommittable = false
98-
myReporter =
99-
if (testReporter == null) new StoreReporter(reporter)
100-
else {
101-
testReporter.reset()
102-
testReporter
103-
}
105+
myReporter = testReporter
104106
try op
105107
finally {
106108
myReporter = savedReporter

0 commit comments

Comments
 (0)