Skip to content

Commit 7dceba3

Browse files
committed
Eliminate some hot allocations
Again, these might be eliminated by escape analysis, but it does not hurt to not allocate in the first place.
1 parent 8175d6a commit 7dceba3

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
5151
else {
5252
val newpd: this.type =
5353
if (mySpan.isSynthetic) {
54-
if (!mySpan.exists && span.exists)
54+
if (!mySpan.exists && span.exists) {
5555
envelope(source, span.startPos) // fill in children spans
56+
() // Note: the `()` is there to prevent some inefficient code from being generated.
57+
// Without it we get an allocation of a span here since the result type of the `if`
58+
// is `Any`, the lub of `Span` and `Unit`.
59+
}
5660
this
5761
}
5862
else cloneIn(source)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ object Names {
570570
*/
571571
def termName(cs: Array[Char], offset: Int, len: Int): SimpleName = synchronized {
572572
util.Stats.record("termName")
573-
val h = hashValue(cs, offset, len) & (table.size - 1)
573+
val h = hashValue(cs, offset, len) & (table.length - 1)
574574

575575
/** Make sure the capacity of the character array is at least `n` */
576576
def ensureCapacity(n: Int) =

0 commit comments

Comments
 (0)