Skip to content

Commit c449be6

Browse files
committed
Prefer ArrayBuffer to List
1 parent 5bb27fd commit c449be6

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
9090

9191
override def settings = currentSettings
9292

93-
override def isSymbolLockTracingEnabled = settings.cyclic
93+
override def isSymbolLockTracingEnabled = settings.cyclic.value
9494

9595
private[this] var currentReporter: FilteringReporter = null
9696
locally { reporter = reporter0 }

src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,13 @@ trait TypeDiagnostics extends splain.SplainDiagnostics {
842842
/** Returns Some(msg) if the given tree is untyped apparently due
843843
* to a cyclic reference, and None otherwise.
844844
*/
845-
def cyclicReferenceMessage(sym: Symbol, tree: Tree, trace: List[Symbol], pos: Position) = {
845+
def cyclicReferenceMessage(sym: Symbol, tree: Tree, trace: Array[Symbol], pos: Position) = {
846846
def symWasOverloaded(sym: Symbol) = sym.owner.isClass && sym.owner.info.member(sym.name).isOverloaded
847847
def cyclicAdjective(sym: Symbol) = if (symWasOverloaded(sym)) "overloaded" else "recursive"
848848

849849
val badsym = if (!sym.isSynthetic) sym else trace.filter(!_.isSynthetic) match {
850-
case badsym :: Nil => badsym
851-
case Nil => sym
850+
case CyclicReference.emptyTrace => sym
851+
case Array(badsym) => badsym
852852
case baddies => baddies.find(_.pos.focus == pos.focus).getOrElse(baddies.head)
853853
}
854854
condOpt(tree) {

src/reflect/scala/reflect/internal/Symbols.scala

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ package scala
1818
package reflect
1919
package internal
2020

21-
import scala.collection.immutable
22-
import scala.collection.mutable.{ListBuffer, Stack}
23-
import util.{ ReusableInstance, Statistics, shortClassOfInstance }
24-
import Flags._
2521
import scala.annotation.tailrec
22+
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
2623
import scala.reflect.io.{AbstractFile, NoAbstractFile}
24+
25+
import util.{ReusableInstance, Statistics, shortClassOfInstance}
26+
import Flags._
2727
import Variance._
2828

2929
trait Symbols extends api.Symbols { self: SymbolTable =>
@@ -36,15 +36,15 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
3636
protected def nextId() = { ids += 1; ids }
3737

3838
/** Used to keep track of the recursion depth on locked symbols */
39-
private[this] var _recursionTable = immutable.Map.empty[Symbol, Int]
39+
private[this] var _recursionTable = Map.empty[Symbol, Int]
4040
def recursionTable = _recursionTable
41-
def recursionTable_=(value: immutable.Map[Symbol, Int]) = _recursionTable = value
41+
def recursionTable_=(value: Map[Symbol, Int]) = _recursionTable = value
4242

4343
private[this] var _lockedCount = 0
4444
def lockedCount = this._lockedCount
4545
def lockedCount_=(i: Int) = _lockedCount = i
4646

47-
private[this] val _lockingTrace = Stack.empty[Symbol]
47+
private[this] val _lockingTrace = ArrayBuffer.empty[Symbol]
4848
private[this] val lockTracing: Boolean = self.isSymbolLockTracingEnabled
4949

5050
@deprecated("Global existential IDs no longer used", "2.12.1")
@@ -568,7 +568,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
568568

569569
// Lock a symbol, using the handler if the recursion depth becomes too great.
570570
private[scala] def lock(handler: => Unit): Boolean = {
571-
if (lockTracing) _lockingTrace.push(this)
571+
if (lockTracing) _lockingTrace.addOne(this)
572572
if ((_rawflags & LOCKED) != 0L) {
573573
if (settings.Yrecursion.value != 0) {
574574
recursionTable.get(this) match {
@@ -599,7 +599,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
599599
if ((_rawflags & LOCKED) != 0L) {
600600
_rawflags &= ~LOCKED
601601
if (lockTracing && !_lockingTrace.isEmpty)
602-
_lockingTrace.remove(idx = 0, count = 1)
602+
_lockingTrace.remove(index = _lockingTrace.size - 1, count = 1) // dropRightInPlace(1)
603603
if (settings.Yrecursion.value != 0)
604604
recursionTable -= this
605605
}
@@ -1565,14 +1565,14 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
15651565
setInfo(ErrorType)
15661566
val trace =
15671567
if (lockTracing) {
1568-
val t = _lockingTrace.toList
1568+
val t = _lockingTrace.toArray
15691569
_lockingTrace.clear()
15701570
t
1571-
} else Nil
1571+
} else CyclicReference.emptyTrace
15721572
throw CyclicReference(this, tp, trace)
15731573
}
15741574
} else {
1575-
if (lockTracing) _lockingTrace.push(this)
1575+
if (lockTracing) _lockingTrace.addOne(this)
15761576
_rawflags |= LOCKED
15771577
}
15781578
val current = phase
@@ -3849,10 +3849,13 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
38493849
else closestEnclMethod(from.owner)
38503850

38513851
/** An exception for cyclic references of symbol definitions */
3852-
case class CyclicReference(sym: Symbol, info: Type, trace: List[Symbol] = Nil)
3852+
case class CyclicReference(sym: Symbol, info: Type, trace: Array[Symbol] = CyclicReference.emptyTrace)
38533853
extends TypeError(s"illegal cyclic reference involving $sym") {
38543854
if (settings.isDebug) printStackTrace()
38553855
}
3856+
object CyclicReference {
3857+
val emptyTrace: Array[Symbol] = Array.empty[Symbol]
3858+
}
38563859

38573860
/** A class for type histories */
38583861
private final case class TypeHistory protected (private var _validFrom: Period, private var _info: Type, private var _prev: TypeHistory) {

0 commit comments

Comments
 (0)