Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. This
change log follows the conventions of
[keepachangelog.com](http://keepachangelog.com/).

## 3.9.3 / 2026-01-22
- Improve performance of in-any-order via memoization

## 3.9.2 / 2025-08-20
- Fix set mismatch info when experimental elision feature is enabled

Expand Down
10 changes: 8 additions & 2 deletions src/cljc/matcher_combinators/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,16 @@
(or (and subset? (empty? unmatched))
(and (not subset?) (empty? unmatched) (empty? elements))))

(def ^:private memo-match
"Memoized version of match for use in `in-any-order`. Helpful because in the
case of a mismatch, `in-any-order` can call match several times on the same
input (to compute weight or minimal mismatch details)."
(memoize match))

(defn- residual-matching-weight [matchers elements]
(reduce (fn [w result] (+ w (::result/weight result)))
0
(map match matchers elements)))
(map memo-match matchers elements)))

(defn- matches-in-any-order? [unmatched elements subset? matching]
(if (or (empty? unmatched) (empty? elements))
Expand All @@ -352,7 +358,7 @@
:elements (concat (map second matching) elements)
:matched (map first matching)})
(let [[matcher & unmatched-rest] unmatched
matching-elem (utils/find-first #(indicates-match? (match matcher %))
matching-elem (utils/find-first #(indicates-match? (memo-match matcher %))
elements)]
(if (nil? matching-elem)
{:matched? false
Expand Down
2 changes: 1 addition & 1 deletion version.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:major 3
:minor 9
:release 2
:release 3
#_#_ :qualifier :alpha}
Loading