Skip to content

Commit 5d550c5

Browse files
committed
Avoid some map and flatMap calls
1 parent 556d10e commit 5d550c5

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ object Types {
829829
*/
830830
final def possibleSamMethods(using Context): Seq[SingleDenotation] = {
831831
record("possibleSamMethods")
832-
abstractTermMembers.filterConserve(m =>
832+
abstractTermMembers.toList.filterConserve(m =>
833833
!m.symbol.matchingMember(defn.ObjectType).exists && !m.symbol.isSuperAccessor)
834834
}
835835

@@ -3180,7 +3180,12 @@ object Types {
31803180
private var myParamRefs: List[ParamRefType] = null
31813181

31823182
def paramRefs: List[ParamRefType] = {
3183-
if (myParamRefs == null) myParamRefs = paramNames.indices.toList.map(newParamRef)
3183+
if myParamRefs == null then
3184+
def recur(paramNames: List[ThisName], i: Int): List[ParamRefType] =
3185+
paramNames match
3186+
case _ :: rest => newParamRef(i) :: recur(rest, i + 1)
3187+
case _ => Nil
3188+
myParamRefs = recur(paramNames, 0)
31843189
myParamRefs
31853190
}
31863191

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import reporting._
2222
import config.Printers.{exhaustivity => debug}
2323
import util.SrcPos
2424
import NullOpsDecorator._
25+
import collection.mutable
2526

2627
/** Space logic for checking exhaustivity and unreachability of pattern matching
2728
*
@@ -123,10 +124,13 @@ trait SpaceLogic {
123124
else if (canDecompose(tp) && decompose(tp).isEmpty) Empty
124125
else sp
125126
case Or(spaces) =>
126-
val set = spaces.map(simplify(_)).flatMap {
127-
case Or(ss) => ss
128-
case s => Seq(s)
129-
}.filterConserve(_ != Empty)
127+
val buf = new mutable.ListBuffer[Space]
128+
def include(s: Space) = if s != Empty then buf += s
129+
for space <- spaces do
130+
simplify(space) match
131+
case Or(ss) => ss.foreach(include)
132+
case s => include(s)
133+
val set = buf.toList
130134

131135
if (set.isEmpty) Empty
132136
else if (set.size == 1) set.toList(0)

0 commit comments

Comments
 (0)