Skip to content

Commit 12f2778

Browse files
committed
Small performance tweak
Useful for the following test: tests/run-custom-args/tuple-cons.scala
1 parent c89c89a commit 12f2778

File tree

1 file changed

+13
-7
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+13
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,21 @@ trait SpaceLogic {
262262
case (Typ(tp1, _), Prod(tp2, _, _, false)) =>
263263
a // approximation
264264
case (Prod(tp1, fun1, ss1, full), Prod(tp2, fun2, ss2, _)) =>
265-
if (!isSameUnapply(fun1, fun2)) a
266-
else if (ss1.zip(ss2).exists(p => isSubspace(p._1, minus(p._1, p._2)))) a
267-
else if (ss1.zip(ss2).forall((isSubspace _).tupled)) Empty
265+
if (!isSameUnapply(fun1, fun2)) return a
266+
267+
val range = (0 until ss1.size).toList
268+
val cache = Array.fill[Space](ss2.length)(null)
269+
def sub(i: Int) =
270+
if cache(i) == null then
271+
cache(i) = minus(ss1(i), ss2(i))
272+
cache(i)
273+
end sub
274+
275+
if range.exists(i => isSubspace(ss1(i), sub(i))) then a
276+
else if cache.forall(sub => isSubspace(sub, Empty)) then Empty
268277
else
269278
// `(_, _, _) - (Some, None, _)` becomes `(None, _, _) | (_, Some, _) | (_, _, Empty)`
270-
Or(ss1.zip(ss2).map((minus _).tupled).zip(0 to ss2.length - 1).map {
271-
case (ri, i) => Prod(tp1, fun1, ss1.updated(i, ri), full)
272-
})
273-
279+
Or(range.map { i => Prod(tp1, fun1, ss1.updated(i, sub(i)), full) })
274280
}
275281
}
276282
}

0 commit comments

Comments
 (0)