Skip to content

Commit 211cc8f

Browse files
Merge pull request #3643 from dotty-staging/optimize/Positions
Micro-optimize Positions
2 parents fd861b0 + d58da55 commit 211cc8f

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

compiler/src/dotty/tools/dotc/util/Positions.scala

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import language.implicitConversions
1111
*/
1212
object Positions {
1313

14-
private val StartEndBits = 26
15-
val StartEndMask: Long = (1L << StartEndBits) - 1
16-
private val SyntheticPointDelta = (1 << (64 - StartEndBits * 2)) - 1
14+
private final val StartEndBits = 26
15+
private final val StartEndMask = (1L << StartEndBits) - 1
16+
private final val SyntheticPointDelta = (1 << (64 - StartEndBits * 2)) - 1
1717

1818
/** The maximal representable offset in a position */
19-
val MaxOffset = StartEndMask
19+
private final val MaxOffset = StartEndMask
2020

2121
/** Convert offset `x` to an integer by sign extending the original
2222
* field of `StartEndBits` width.
@@ -134,18 +134,13 @@ object Positions {
134134
}
135135

136136
/** A synthetic position with given start and end */
137-
def Position(start: Int, end: Int): Position = {
138-
val pos = fromOffsets(start, end, SyntheticPointDelta)
139-
assert(pos.isSynthetic)
140-
pos
141-
}
137+
def Position(start: Int, end: Int): Position =
138+
fromOffsets(start, end, SyntheticPointDelta)
142139

143140
/** A source-derived position with given start, end, and point delta */
144141
def Position(start: Int, end: Int, point: Int): Position = {
145142
val pointDelta = (point - start) max 0
146-
val pos = fromOffsets(start, end, if (pointDelta >= SyntheticPointDelta) 0 else pointDelta)
147-
assert(pos.isSourceDerived)
148-
pos
143+
fromOffsets(start, end, if (pointDelta >= SyntheticPointDelta) 0 else pointDelta)
149144
}
150145

151146
/** A synthetic zero-extent position that starts and ends at given `start`. */

0 commit comments

Comments
 (0)