Permalink
Browse files

refactor or patterns

  • Loading branch information...
1 parent d2b6213 commit a62169f635aa831b23329f4a758d4dc1ab29e33d @swannodette swannodette committed May 10, 2013
Showing with 13 additions and 13 deletions.
  1. +13 −13 src/main/clojure/clojure/core/match.clj
@@ -1318,6 +1318,17 @@
;; -----------------------------------------------------------------------------
;; Or Patterns
+(defn specialize-or-pattern-row [row pat ps]
+ (let [p (first row)]
+ ;; NOTE: hmm why can't we remove this - David
+ (if (and (pattern-equals pat p)
+ (not (wildcard-pattern? p)))
+ (map (fn [p] (update-pattern row 0 p)) ps) [row])))
+
+(defn specialize-or-pattern-matrix [rows pat ps]
+ (vec (apply concat
+ (map #(specialize-or-pattern-row % pat ps) rows))))
+
(deftype OrPattern [ps _meta]
clojure.lang.IObj
(meta [_] _meta)
@@ -1328,19 +1339,8 @@
(str ps))
ISpecializeMatrix
(specialize-matrix [this rows ocrs]
- (let [ps (.ps this)
- nrows (->> rows
- (map (fn [row]
- (let [p (first row)]
- ;; NOTE: hmm why can't we remove this - David
- (if (and (pattern-equals this p)
- (not (wildcard-pattern? p)))
- (map (fn [p]
- (update-pattern row 0 p)) ps)
- [row]))))
- (apply concat)
- vec)
- _ (trace-dag "OrPattern specialization")]
+ (let [nrows (specialize-or-pattern-matrix rows this ps)
+ _ (trace-dag "OrPattern specialization")]
(pattern-matrix nrows ocrs))))
(defn ^OrPattern or-pattern [p]

0 comments on commit a62169f

Please sign in to comment.