@@ -31,12 +31,13 @@ object Matcher {
3131 * @return None if it did not match, `Some(tup)` if it matched where `tup` contains `Expr[Ti]``
3232 */
3333 def unapply [Tup <: Tuple ](scrutineeExpr : Expr [_])(implicit patternExpr : Expr [_], reflection : Reflection ): Option [Tup ] = {
34+ // TODO improve performance
3435 import reflection .{Bind => BindPattern , _ }
3536 import Matching ._
3637
3738 type Env = Set [(Symbol , Symbol )]
3839
39- // TODO improve performance
40+ inline def withEnv [ T ]( env : Env )( body : given Env => T ) : T = body given env
4041
4142 /** Check that the trees match and return the contents from the pattern holes.
4243 * Return None if the trees do not match otherwise return Some of a tuple containing all the contents in the holes.
@@ -120,10 +121,7 @@ object Matcher {
120121 fn1 =#= fn2 && args1 =##= args2
121122
122123 case (Block (stats1, expr1), Block (stats2, expr2)) =>
123- val env = the[Env ] ++ stats1.map(_.symbol).zip(stats2.map(_.symbol))
124-
125- {
126- implied for Env = env
124+ withEnv(the[Env ] ++ stats1.map(_.symbol).zip(stats2.map(_.symbol))) {
127125 stats1 =##= stats2 && expr1 =#= expr2
128126 }
129127
@@ -247,9 +245,7 @@ object Matcher {
247245
248246 def caseMatches (scrutinee : CaseDef , pattern : CaseDef ) given Env : Matching = {
249247 val (caseEnv, patternMatch) = scrutinee.pattern =%= pattern.pattern
250-
251- {
252- implied for Env = caseEnv
248+ withEnv(caseEnv) {
253249 val guardMatch = treeOptMatches(scrutinee.guard, pattern.guard)
254250 val rhsMatch = scrutinee.rhs =#= pattern.rhs
255251 patternMatch && guardMatch && rhsMatch
0 commit comments