Skip to content

Commit b9f4ccc

Browse files
committed
Generate less code in 'throw-condition'.
1 parent 87ce235 commit b9f4ccc

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/active/clojure/condition.cljc

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,22 +370,28 @@
370370
make-throwable throwable?
371371
[^{:doc "Throwable object"} value throwable-value])
372372

373+
(defn ^:no-doc build-condition [base who message ?irritants]
374+
(let [g (group-by (fn [thing]
375+
(or (condition? thing)
376+
#?(:cljs (instance? js/Error thing)
377+
:clj (instance? Throwable thing))))
378+
?irritants)
379+
irritants (get g false)
380+
conditions (get g true)]
381+
(apply combine-conditions
382+
base
383+
(and who (make-who-condition who))
384+
(make-message-condition message)
385+
(and (not-empty irritants) (make-irritants-condition irritants))
386+
conditions)))
387+
373388
#?(:clj
374389
(defmacro throw-condition
375390
"Throw a condition.
376391
377392
For internal use."
378393
[?base ?who ?message ?irritants]
379-
`(let [g# (group-by (fn [thing#] (or (condition? thing#) (if-cljs (instance? js/Error thing#) (instance? Throwable thing#)))) ~?irritants)
380-
irritants# (get g# false)
381-
conditions# (get g# true)
382-
who# ~?who]
383-
(throw (apply combine-conditions
384-
~?base
385-
(and who# (make-who-condition who#))
386-
(make-message-condition ~?message)
387-
(and (not-empty irritants#) (make-irritants-condition irritants#))
388-
conditions#)))))
394+
`(throw (build-condition ~?base ~?who ~?message ~?irritants))))
389395

390396
(defn error
391397
"Throw an exception that signals that an error has occurred.

0 commit comments

Comments
 (0)