Skip to content

Commit 0d01e22

Browse files
committed
More perf?
1 parent f922858 commit 0d01e22

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ object Periods {
5454

5555
/** Does this period contain the given period? */
5656
def contains(that: Period): Boolean =
57-
this.runId == that.runId &&
58-
this.firstPhaseId <= that.firstPhaseId &&
59-
that.lastPhaseId <= this.lastPhaseId
57+
// We want to check (run1 == run2) & (last1 >= last2) & (first1 <= first2).
58+
// We can do the first two comparisons in one by checking if subtracting code1 from code2 leads to all-zeroes
59+
// in the sign + run ID bits. If (run1 > run2) or (run2 < run1) or (run1 == run2 and last1 < last2),
60+
// then (code1 - code2) is either large enough to have some run ID bits set, or negative so the sign bit is set.
61+
((this.code - that.code) & (-1 << (PhaseWidth * 2))) == 0 &&
62+
this.firstPhaseId <= that.firstPhaseId
6063

6164
/** Does this period overlap with given period? */
6265
def overlaps(that: Period): Boolean =

0 commit comments

Comments
 (0)