Skip to content

Commit c80d9a8

Browse files
committed
Avoid more collection ops in frontend
1 parent 63010f7 commit c80d9a8

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,13 @@ object SymDenotations {
15561556
completeChildrenIn(companionClass)
15571557
setFlag(ChildrenQueried)
15581558

1559-
annotations.collect { case Annotation.Child(child) => child }.reverse
1559+
/** The children recorded in `annots`, in reverse order */
1560+
def getChildren(annots: List[Annotation], acc: List[Symbol]): List[Symbol] = annots match
1561+
case Annotation.Child(child) :: annots1 => getChildren(annots1, child :: acc)
1562+
case _ :: annots1 => getChildren(annots1, acc)
1563+
case nil => acc
1564+
1565+
getChildren(annotations, Nil)
15601566
end children
15611567
}
15621568

compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ class NameBuffer extends TastyBuffer(10000) {
9797
}
9898
}
9999

100-
override def assemble(): Unit = {
100+
override def assemble(): Unit =
101101
var i = 0
102-
for ((name, ref) <- nameRefs) {
102+
val nr = nameRefs.iterator
103+
while nr.hasNext do
104+
val (name, ref) = nr.next()
103105
assert(ref.index == i)
104106
i += 1
105107
pickleNameContents(name)
106-
}
107-
}
108108
}
109109

110110
object NameBuffer {

compiler/src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ object SymUtils {
2222

2323
extension (self: Symbol) {
2424

25-
/** All traits implemented by a class or trait except for those inherited through the superclass. */
25+
/** All traits implemented by a class or trait except for those inherited
26+
* through the superclass. Traits are given in the order they appear in the
27+
* parents clause (which is the reverse of their order in baseClasses)
28+
*/
2629
def directlyInheritedTraits(using Context): List[ClassSymbol] = {
2730
val superCls = self.asClass.superClass
2831
val baseClasses = self.asClass.baseClasses
2932
if (baseClasses.isEmpty) Nil
30-
else baseClasses.tail.takeWhile(_ ne superCls).reverse
33+
else
34+
def recur(bcs: List[ClassSymbol], acc: List[ClassSymbol]): List[ClassSymbol] = bcs match
35+
case bc :: bcs1 => if bc eq superCls then acc else recur(bcs1, bc :: acc)
36+
case nil => acc
37+
recur(baseClasses.tail, Nil)
3138
}
3239

3340
/** All traits implemented by a class, except for those inherited through the superclass.

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,9 @@ object RefChecks {
491491
*/
492492
def missingTermSymbols: List[Symbol] =
493493
val buf = new mutable.ListBuffer[Symbol]
494-
for bc <- clazz.baseClasses
495-
sym <- bc.info.decls.toList
496-
if sym.is(DeferredTerm) && !isImplemented(sym) && !ignoreDeferred(sym)
497-
do buf += sym
494+
for bc <- clazz.baseClasses; sym <- bc.info.decls.toList do
495+
if sym.is(DeferredTerm) && !isImplemented(sym) && !ignoreDeferred(sym)
496+
buf += sym
498497
buf.toList
499498

500499
// 2. Check that only abstract classes have deferred members

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,21 +1223,24 @@ class Typer extends Namer
12231223
}
12241224

12251225
val desugared =
1226-
if (protoFormals.length == 1 && params.length != 1 && ptIsCorrectProduct(protoFormals.head)) {
1226+
if (protoFormals.length == 1 && params.length != 1 && ptIsCorrectProduct(protoFormals.head))
12271227
val isGenericTuple =
12281228
protoFormals.head.derivesFrom(defn.TupleClass)
12291229
&& !defn.isTupleClass(protoFormals.head.typeSymbol)
12301230
desugar.makeTupledFunction(params, fnBody, isGenericTuple)
1231-
}
1232-
else {
1233-
val inferredParams: List[untpd.ValDef] =
1234-
for ((param, i) <- params.zipWithIndex) yield
1235-
if (!param.tpt.isEmpty) param
1236-
else cpy.ValDef(param)(
1237-
tpt = untpd.TypeTree(
1238-
inferredParamType(param, protoFormal(i)).translateFromRepeated(toArray = false)))
1239-
desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual)
1240-
}
1231+
else
1232+
def inferredParams(params: List[untpd.ValDef], idx: Int): List[untpd.ValDef] = params match
1233+
case param :: rest =>
1234+
val param1 =
1235+
if !param.tpt.isEmpty then param
1236+
else cpy.ValDef(param)(
1237+
tpt = untpd.TypeTree(
1238+
inferredParamType(param, protoFormal(idx)).translateFromRepeated(toArray = false)))
1239+
param1 :: inferredParams(rest, idx + 1)
1240+
case nil =>
1241+
Nil
1242+
desugar.makeClosure(inferredParams(params, 0), fnBody, resultTpt, isContextual)
1243+
12411244
typed(desugared, pt)
12421245
}
12431246

0 commit comments

Comments
 (0)