Skip to content

Commit 0bf4c3f

Browse files
authored
More DCE cleanup (#253)
Tiny DCE improvements - just use empty list in IndexedSeq - just invoke toString on StringBuffer - inline toString impl for EmptyList - reify should not emit basis static method - reify should set meta to nil if no actual meta, not empty map
1 parent 4d13556 commit 0bf4c3f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@
909909
writer (StringBufferWriter. sb)]
910910
(-pr-writer obj writer (pr-opts))
911911
(-flush writer)
912-
(str sb)))
912+
(.toString sb)))
913913

914914
;;;;;;;;;;;;;;;;;;; Murmur3 ;;;;;;;;;;;;;;;
915915

@@ -1648,7 +1648,7 @@ reduces them without incurring seq initialization"
16481648
(-first [_] (aget arr i))
16491649
(-rest [_] (if (< (inc i) (alength arr))
16501650
(IndexedSeq. arr (inc i) nil)
1651-
(list)))
1651+
()))
16521652

16531653
INext
16541654
(-next [_] (if (< (inc i) (alength arr))
@@ -3206,8 +3206,7 @@ reduces them without incurring seq initialization"
32063206

32073207
(deftype EmptyList [meta]
32083208
Object
3209-
(toString [coll]
3210-
(pr-str* coll))
3209+
(toString [coll] "()")
32113210
(equiv [this other]
32123211
(-equiv this other))
32133212
(indexOf [coll x]

src/main/clojure/cljs/core.cljc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@
13651365
[& impls]
13661366
(core/let [t (with-meta
13671367
(gensym
1368-
(core/str "t_"
1368+
(core/str "t_reify_"
13691369
(string/replace (core/str (munge ana/*cljs-ns*)) "." "$")))
13701370
{:anonymous true})
13711371
meta-sym (gensym "meta")
@@ -1382,7 +1382,11 @@
13821382
IMeta
13831383
(~'-meta [~this-sym] ~meta-sym)
13841384
~@impls))
1385-
(new ~t ~@locals ~(ana/elide-reader-meta (meta &form))))))
1385+
(new ~t ~@locals
1386+
;; if the form meta is empty, emit nil
1387+
~(core/let [form-meta (ana/elide-reader-meta (meta &form))]
1388+
(core/when-not (empty? form-meta)
1389+
form-meta))))))
13861390

13871391
(core/defmacro specify!
13881392
"Identical to reify but mutates its first argument."
@@ -1789,17 +1793,22 @@
17891793
[t fields & impls]
17901794
(validate-fields "deftype" t fields)
17911795
(core/let [env &env
1792-
r (:name (cljs.analyzer/resolve-var (dissoc env :locals) t))
1796+
v (cljs.analyzer/resolve-var (dissoc env :locals) t)
1797+
r (:name v)
17931798
[fpps pmasks] (prepare-protocol-masks env impls)
17941799
protocols (collect-protocols impls env)
17951800
t (vary-meta t assoc
17961801
:protocols protocols
1797-
:skip-protocol-flag fpps) ]
1802+
:skip-protocol-flag fpps)]
17981803
`(do
17991804
(deftype* ~t ~fields ~pmasks
18001805
~(if (seq impls)
18011806
`(extend-type ~t ~@(dt->et t impls fields))))
1802-
(set! (.-getBasis ~t) (fn [] '[~@fields]))
1807+
;; don't emit static basis method w/ reify
1808+
;; nor for core types
1809+
~@(core/when-not (core/or (string/starts-with? (name t) "t_reify")
1810+
(= 'cljs.core (:ns v)))
1811+
[`(set! (.-getBasis ~t) (fn [] '[~@fields]))])
18031812
(set! (.-cljs$lang$type ~t) true)
18041813
(set! (.-cljs$lang$ctorStr ~t) ~(core/str r))
18051814
(set! (.-cljs$lang$ctorPrWriter ~t) (fn [this# writer# opt#] (-write writer# ~(core/str r))))

0 commit comments

Comments
 (0)