Skip to content

Commit f0e76c3

Browse files
committed
cleanup
- remove simple-map-entry, more trouble than it's worth hassle, and does really save any spaced since need to implement everything to pass tests - add trivial.core6 size ratchet
1 parent 7d8ee19 commit f0e76c3

File tree

5 files changed

+28
-89
lines changed

5 files changed

+28
-89
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10384,56 +10384,6 @@ reduces them without incurring seq initialization"
1038410384

1038510385
(declare Vector)
1038610386

10387-
(defn- simple-map-entry [k v]
10388-
(reify
10389-
ICounted
10390-
(-count [coll] 2)
10391-
IHash
10392-
(-hash [coll] (hash-ordered-coll [k v]))
10393-
ISequential
10394-
IEquiv
10395-
(-equiv [coll other] (equiv-sequential coll other))
10396-
IVector
10397-
(-assoc-n [_ n x]
10398-
(case n
10399-
0 (simple-map-entry x v)
10400-
1 (simple-map-entry k x)
10401-
(throw (js/Error. "Index out of bounds"))))
10402-
IAssociative
10403-
(-assoc [node k v]
10404-
(-assoc-n node k v))
10405-
(-contains-key? [node k]
10406-
(or (== k 0) (== k 1)))
10407-
ICollection
10408-
(-conj [coll x]
10409-
(if ^boolean LITE_MODE
10410-
(Vector. nil #js [k v x] nil)
10411-
[k v x]))
10412-
IMapEntry
10413-
(-key [_] k)
10414-
(-val [_] v)
10415-
ISeqable
10416-
(-seq [_] (IndexedSeq. #js [k v] 0 nil))
10417-
IIndexed
10418-
(-nth [_ i]
10419-
(case i, 0 k, 1 v, (throw (js/Error. "Index out of bounds"))))
10420-
(-nth [_ i not-found]
10421-
(case i, 0 k, 1 v, not-found))
10422-
ILookup
10423-
(-lookup [coll k] (-nth coll k nil))
10424-
(-lookup [coll k not-found] (-nth coll k not-found))
10425-
IFind
10426-
(-find [node x]
10427-
(case x
10428-
0 (simple-map-entry 0 k)
10429-
1 (simple-map-entry 1 v)
10430-
nil))
10431-
IFn
10432-
(-invoke [coll k]
10433-
(-nth coll k))
10434-
(-invoke [coll k not-found]
10435-
(-nth coll k not-found))))
10436-
1043710387
(defn- pr-writer-impl
1043810388
[obj writer opts]
1043910389
(cond
@@ -10472,9 +10422,10 @@ reduces them without incurring seq initialization"
1047210422
(.map
1047310423
(js-keys obj)
1047410424
(fn [k]
10475-
(simple-map-entry
10425+
(MapEntry.
1047610426
(cond-> k (some? (.match k #"^[A-Za-z_\*\+\?!\-'][\w\*\+\?!\-']*$")) keyword)
10477-
(unchecked-get obj k))))
10427+
(unchecked-get obj k)
10428+
nil)))
1047810429
pr-writer writer opts))
1047910430

1048010431
(array? obj)
@@ -10655,10 +10606,10 @@ reduces them without incurring seq initialization"
1065510606
(when (or (keyword? k) (symbol? k))
1065610607
(if ns
1065710608
(when (= ns (namespace k))
10658-
(.push lm (simple-map-entry (strip-ns k) v))
10609+
(.push lm (MapEntry. (strip-ns k) v nil))
1065910610
(recur ns entries))
1066010611
(when-let [new-ns (namespace k)]
10661-
(.push lm (simple-map-entry (strip-ns k) v))
10612+
(.push lm (MapEntry. (strip-ns k) v nil))
1066210613
(recur new-ns entries))))
1066310614
#js [ns lm])))))
1066410615

@@ -12566,7 +12517,7 @@ reduces them without incurring seq initialization"
1256612517
(next [_]
1256712518
(let [k (aget strkeys i)]
1256812519
(set! i (inc i))
12569-
(simple-map-entry (obj-map-key->keyword k) (unchecked-get strobj k)))))
12520+
(MapEntry. (obj-map-key->keyword k) (unchecked-get strobj k) nil))))
1257012521

1257112522
(deftype ObjMap [meta strkeys strobj ^:mutable __hash]
1257212523
Object
@@ -12621,7 +12572,7 @@ reduces them without incurring seq initialization"
1262112572
(when (pos? (alength strkeys))
1262212573
(prim-seq
1262312574
(.map (.sort strkeys obj-map-compare-keys)
12624-
#(simple-map-entry (obj-map-key->keyword %) (unchecked-get strobj %))))))
12575+
#(MapEntry. (obj-map-key->keyword %) (unchecked-get strobj %) nil)))))
1262512576

1262612577
ICounted
1262712578
(-count [coll] (alength strkeys))
@@ -12822,7 +12773,7 @@ reduces them without incurring seq initialization"
1282212773
(loop [j 0]
1282312774
(when (< j len)
1282412775
(do
12825-
(.push arr (simple-map-entry (aget bckt j) (aget bckt (inc j))))
12776+
(.push arr (MapEntry. (aget bckt j) (aget bckt (inc j)) nil))
1282612777
(recur (+ j 2)))))
1282712778
(recur (inc i)))
1282812779
(prim-seq arr))))))

src/test/cljs/cljs/collections_test.cljs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,12 +1216,6 @@
12161216
(is (= (simple-set [[3 4] [1 2] [5 6]])
12171217
(into #{} [[3 4] [1 2] [5 6]]))))
12181218

1219-
(deftest test-simple-map-entry
1220-
(is (= (simple-map-entry :foo 1)
1221-
(MapEntry. :foo 1 nil)))
1222-
(is (= (hash (simple-map-entry :foo 1))
1223-
(hash (MapEntry. :foo 1 nil)))))
1224-
12251219
(comment
12261220

12271221
(run-tests)

src/test/cljs/cljs/lite_collections_test.cljs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,12 @@
1818
(let [a {:foo 1}]
1919
(is (== 1 (:foo a)))))
2020

21-
(deftest test-simple-map-entry-eq-hash
22-
(is (= (simple-map-entry 1 2) (simple-map-entry 1 2)))
23-
(is (= (simple-map-entry 1 2)
24-
(MapEntry. 1 2 nil)))
25-
(is (== (hash (simple-map-entry 1 2))
26-
(hash (MapEntry. 1 2 nil)))))
27-
2821
(deftest test-simple-set-with-set
2922
(is (= (simple-set []) (set [])))
3023
(is (= (set []) (simple-set [])))
31-
(is (= (simple-set [(simple-map-entry 1 2)])
24+
(is (= (simple-set [(MapEntry. 1 2 nil)])
3225
(set [(MapEntry. 1 2 nil)]))))
3326

34-
(deftest test-hash-map-simple-map-entry
35-
(let [m (assoc (. HashMap -EMPTY) (simple-map-entry 1 2) true)]
36-
(is (contains? m (simple-map-entry 1 2)))))
37-
38-
(deftest test-simple-set-simple-map-entry
39-
(let [a (simple-set [(simple-map-entry 1 2)])]
40-
(is (contains? a (simple-map-entry 1 2)))))
41-
42-
(deftest test-simple-map-entry-lookups
43-
(let [me (simple-map-entry :foo "bar")]
44-
(is (= :foo (get me 0)))
45-
(is (= "bar" (get me 1)))
46-
(is (= [0 :foo]
47-
(vec (find (simple-map-entry :foo "bar") 0))))
48-
(is (= [:foo "b"]
49-
(vec (update (simple-map-entry :foo "bar") 1 first))
50-
(vec (update-in (simple-map-entry :foo "bar") [1] first))))))
51-
5227
(comment
5328

5429
(require '[cljs.lite-collections-test] :reload)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(ns trivial.core6)
2+
3+
(.log js/console (->> (map inc (range 10)) (filter even?) (partition 2) (drop 1) (mapcat identity) into-array)})

src/test/clojure/cljs/build_api_tests.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,22 @@
804804
(build/build (build/inputs (io/file inputs "trivial/core5.cljs")) opts cenv)
805805
(is (< (.length out-file) 32768)))))
806806

807+
(deftest lite-mode-api-code-size-ratchet
808+
(testing ":lite-mode + :elide-to-string, typical cljs.core api usage < 32K"
809+
(let [out (.getPath (io/file (test/tmp-dir) "trivial-output-map-test-out"))
810+
out-file (io/file out "main.js")
811+
{:keys [inputs opts]} {:inputs (str (io/file "src" "test" "cljs_build"))
812+
:opts {:main 'trivial.core6
813+
:output-dir out
814+
:output-to (.getPath out-file)
815+
:lite-mode true
816+
:elide-to-string true
817+
:optimizations :advanced}}
818+
cenv (env/default-compiler-env)]
819+
(test/delete-out-files out)
820+
(build/build (build/inputs (io/file inputs "trivial/core6.cljs")) opts cenv)
821+
(is (< (.length out-file) 32768)))))
822+
807823
(deftest cljs-3255-nil-inputs-build
808824
(let [out (.getPath (io/file (test/tmp-dir) "3255-test-out"))
809825
out-file (io/file out "main.js")

0 commit comments

Comments
 (0)