Skip to content
Browse files

* src/clj/cljs/core.clj: use transient vector in read-delimited-list.…

… case macro now emits more efficient code.
  • Loading branch information...
1 parent 8ffb946 commit b9f25041465b0f911459f0e28ec2f65aab27ca7c David Nolen committed May 10, 2012
Showing with 7 additions and 7 deletions.
  1. +3 −3 src/clj/cljs/core.clj
  2. +4 −4 src/cljs/cljs/reader.cljs
View
6 src/clj/cljs/core.clj
@@ -641,9 +641,9 @@
(last clauses)
`(throw (js/Error. (core/str "No matching clause: " ~e))))
pairs (partition 2 clauses)]
- `(condp = ~e
- ~@(apply concat pairs)
- ~default)))
+ `(cond
+ ~@(mapcat (fn [[m c]] `((identical? ~m ~e) ~c)) pairs)
+ :else ~default)))
(defmacro try
"(try expr* catch-clause* finally-clause?)
View
8 src/cljs/cljs/reader.cljs
@@ -193,18 +193,18 @@ nil if the end of stream has been reached")
(defn read-delimited-list
[delim rdr recursive?]
- (loop [a []]
+ (loop [a (transient [])]
(let [ch (read-past whitespace? rdr)]
(when-not ch (reader-error rdr "EOF"))
(if (identical? delim ch)
- a
+ (persistent! a)
(if-let [macrofn (macros ch)]
(let [mret (macrofn rdr ch)]
- (recur (if (identical? mret rdr) a (conj a mret))))
+ (recur (if (identical? mret rdr) a (conj! a mret))))
(do
(unread rdr ch)
(let [o (read rdr true nil recursive?)]
- (recur (if (identical? o rdr) a (conj a o))))))))))
+ (recur (if (identical? o rdr) a (conj! a o))))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; data structure readers

0 comments on commit b9f2504

Please sign in to comment.
Something went wrong with that request. Please try again.