Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* src/main/clojure/clojure/core/match/array.clj: MATCH-26: fixed. min…

…or formatting. fix regression arround custom vector pattern matching.
  • Loading branch information...
commit efa880320fc235536690ba8af078a59c17f3321d 1 parent a117d59
@swannodette swannodette authored
View
6 src/main/clojure/clojure/core/match/array.clj
@@ -116,7 +116,6 @@
(balance-array node)))))
)
- ;; 90ms
(do
(defn balance-array [^objects node]
(matchv ::objects [node]
@@ -125,7 +124,7 @@
(object-array [:black a x b]) y
(object-array [:black c z d])])))
- ;; 360ms
+ ;; 90ms
(let [^objects node (object-array [:black
(object-array [:red
(object-array [:red nil nil nil]) nil nil]) nil nil])]
@@ -201,7 +200,8 @@
[([:black [:red [:red a x b] y c] z d] |
[:black [:red a x [:red b y c]] z d] |
[:black a x [:red [:red b y c] z d]] |
- [:black a x [:red b y [:red c z d]]])] (R (B a x b) y (B c z d))))
+ [:black a x [:red b y [:red c z d]]])] (R (B a x b) y (B c z d))
+ :else node))
;; 200ms
(let [^objects node (B (R (R nil nil nil) nil nil) nil nil)]
View
12 src/main/clojure/clojure/core/match/core.clj
@@ -150,28 +150,38 @@
(defmethod check-size? :default
[_] true)
+
(defmethod tag :default
[t] (throw (Exception. (str "No tag specified for vector specialization " t))))
(defmethod tag ::vector
[_] clojure.lang.IPersistentVector)
+
(defn with-tag [t ocr]
(let [the-tag (tag t)
the-tag (if (.isArray ^Class the-tag)
(.getName ^Class the-tag)
the-tag)]
(with-meta ocr (assoc (ocr meta) :tag the-tag))))
+
(defmethod test-inline ::vector
- [t ocr] `(vector? ~ocr))
+ [t ocr] (if (= t ::vector)
+ `(vector? ~ocr)
+ `(instance? ~(tag t) ~ocr)))
+
(defmethod test-with-size-inline ::vector
[t ocr size] `(and ~(test-inline t ocr) (= ~(count-inline t (with-tag t ocr)) ~size)))
+
(defmethod count-inline ::vector
[_ ocr] `(count ~ocr))
+
(defmethod nth-inline ::vector
[_ ocr i] `(nth ~ocr ~i))
+
(defmethod nth-offset-inline ::vector
[t ocr i offset]
(nth-inline t ocr i))
+
(defmethod subvec-inline ::vector
([_ ocr start] `(subvec ~ocr ~start))
([_ ocr start end] `(subvec ~ocr ~start ~end)))
Please sign in to comment.
Something went wrong with that request. Please try again.