Skip to content

Commit 0639d28

Browse files
committed
Traverse lists only once
1 parent 615dc05 commit 0639d28

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

library/src-3.x/scala/internal/quoted/Matcher.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ object Matcher {
4040
inline def withEnv[T](env: Env)(body: => given Env => T): T = body given env
4141

4242
/** Check that all trees match with =#= and concatenate the results with && */
43-
def (scrutinees: List[Tree]) =##= (patterns: List[Tree]) given Env: Matching =
44-
if (scrutinees.size != patterns.size) notMatched
45-
else foldMatchings(scrutinees.zip(patterns).map((s, p) => s =#= p): _*)
43+
def (scrutinees: List[Tree]) =##= (patterns: List[Tree]) given Env: Matching = {
44+
def rec(l1: List[Tree], l2: List[Tree]): Matching = (l1, l2) match {
45+
case (x :: xs, y :: ys) => x =#= y && rec(xs, ys)
46+
case (Nil, Nil) => matched
47+
case _ => notMatched
48+
}
49+
rec(scrutinees, patterns)
50+
}
4651

4752
/** Check that the trees match and return the contents from the pattern holes.
4853
* Return None if the trees do not match otherwise return Some of a tuple containing all the contents in the holes.

0 commit comments

Comments
 (0)