Skip to content

Commit 67ee02b

Browse files
committed
- before core fns knew about the ObjMap key rep - now it needs to be an internal detail
- testing stuff wip
1 parent 1967067 commit 67ee02b

File tree

4 files changed

+90
-39
lines changed

4 files changed

+90
-39
lines changed

resources/lite_test.edn

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{:optimizations :advanced
2+
:main lite-test-runner
3+
:output-to "builds/out-lite/lite-test.js"
4+
:output-dir "builds/out-lite"
5+
:output-wrapper true
6+
:verbose true
7+
:compiler-stats true
8+
:parallel-build true
9+
:closure-warnings {:non-standard-jsdoc :off :global-this :off}
10+
:language-out :es5}

src/main/cljs/cljs/core.cljs

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12371,9 +12371,9 @@ reduces them without incurring seq initialization"
1237112371
(let [a (hash a)
1237212372
b (hash b)]
1237312373
(cond
12374-
(< a b) -1
12375-
(> a b) 1
12376-
:else 0)))
12374+
(< a b) -1
12375+
(> a b) 1
12376+
:else 0)))
1237712377

1237812378
(defn- obj-clone [obj ks]
1237912379
(let [new-obj (js-obj)
@@ -12387,6 +12387,10 @@ reduces them without incurring seq initialization"
1238712387

1238812388
(declare simple-hash-map)
1238912389

12390+
(defn- keyword->obj-map-key
12391+
[k]
12392+
(str "\uFDD0" "'" (. k -fqn)))
12393+
1239012394
(deftype ObjMap [meta keys strobj ^:mutable __hash]
1239112395
IWithMeta
1239212396
(-with-meta [coll meta] (ObjMap. meta keys strobj __hash))
@@ -12422,41 +12426,45 @@ reduces them without incurring seq initialization"
1242212426
ILookup
1242312427
(-lookup [coll k] (-lookup coll k nil))
1242412428
(-lookup [coll k not-found]
12425-
(if (and (string? k)
12426-
(not (nil? (scan-array 1 k keys))))
12427-
(unchecked-get strobj k)
12428-
not-found))
12429+
(let [k (if-not (keyword? k) k (keyword->obj-map-key k))]
12430+
(if (and (string? k)
12431+
(not (nil? (scan-array 1 k keys))))
12432+
(unchecked-get strobj k)
12433+
not-found)))
1242912434

1243012435
IAssociative
1243112436
(-assoc [coll k v]
12432-
(if (string? k)
12433-
(if-not (nil? (scan-array 1 k keys))
12434-
(let [new-strobj (obj-clone strobj keys)]
12435-
(gobject/set new-strobj k v)
12436-
(ObjMap. meta keys new-strobj nil)) ;overwrite
12437-
(let [new-strobj (obj-clone strobj keys) ; append
12438-
new-keys (aclone keys)]
12439-
(gobject/set new-strobj k v)
12440-
(.push new-keys k)
12441-
(ObjMap. meta new-keys new-strobj nil)))
12442-
; non-string key. game over.
12443-
(-with-meta
12444-
(-kv-reduce coll
12445-
(fn [ret k v]
12446-
(-assoc ret k v))
12447-
(. HashMap -EMPTY) )
12448-
meta)))
12437+
(let [k (if-not (keyword? k) k (keyword->obj-map-key k))]
12438+
(if (string? k)
12439+
(if-not (nil? (scan-array 1 k keys))
12440+
(let [new-strobj (obj-clone strobj keys)]
12441+
(gobject/set new-strobj k v)
12442+
(ObjMap. meta keys new-strobj nil)) ;overwrite
12443+
(let [new-strobj (obj-clone strobj keys) ; append
12444+
new-keys (aclone keys)]
12445+
(gobject/set new-strobj k v)
12446+
(.push new-keys k)
12447+
(ObjMap. meta new-keys new-strobj nil)))
12448+
; non-string key. game over.
12449+
(-with-meta
12450+
(-kv-reduce coll
12451+
(fn [ret k v]
12452+
(-assoc ret k v))
12453+
(. HashMap -EMPTY))
12454+
meta))))
1244912455
(-contains-key? [coll k]
12450-
(if (and (string? k)
12451-
(not (nil? (scan-array 1 k keys))))
12452-
true
12453-
false))
12456+
(let [k (if-not (keyword? k) k (keyword->obj-map-key k))]
12457+
(if (and (string? k)
12458+
(not (nil? (scan-array 1 k keys))))
12459+
true
12460+
false)))
1245412461

1245512462
IFind
1245612463
(-find [coll k]
12457-
(when (and (string? k)
12458-
(not (nil? (scan-array 1 k keys))))
12459-
(MapEntry. k (unchecked-get strobj k) nil)))
12464+
(let [k (if-not (keyword? k) k (keyword->obj-map-key k))]
12465+
(when (and (string? k)
12466+
(not (nil? (scan-array 1 k keys))))
12467+
(MapEntry. k (unchecked-get strobj k) nil))))
1246012468

1246112469
IKVReduce
1246212470
(-kv-reduce [coll f init]
@@ -12473,14 +12481,15 @@ reduces them without incurring seq initialization"
1247312481

1247412482
IMap
1247512483
(-dissoc [coll k]
12476-
(if (and (string? k)
12477-
(not (nil? (scan-array 1 k keys))))
12478-
(let [new-keys (aclone keys)
12479-
new-strobj (obj-clone strobj keys)]
12480-
(.splice new-keys (scan-array 1 k new-keys) 1)
12481-
(js-delete new-strobj k)
12482-
(ObjMap. meta new-keys new-strobj nil))
12483-
coll)) ; key not found, return coll unchanged
12484+
(let [k (if-not (keyword? k) k (keyword->obj-map-key k))]
12485+
(if (and (string? k)
12486+
(not (nil? (scan-array 1 k keys))))
12487+
(let [new-keys (aclone keys)
12488+
new-strobj (obj-clone strobj keys)]
12489+
(.splice new-keys (scan-array 1 k new-keys) 1)
12490+
(js-delete new-strobj k)
12491+
(ObjMap. meta new-keys new-strobj nil))
12492+
coll))) ; key not found, return coll unchanged
1248412493

1248512494
IFn
1248612495
(-invoke [coll k]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; Copyright (c) Rich Hickey. All rights reserved.
2+
; The use and distribution terms for this software are covered by the
3+
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+
; which can be found in the file epl-v10.html at the root of this distribution.
5+
; By using this software in any fashion, you are agreeing to be bound by
6+
; the terms of this license.
7+
; You must not remove this notice, or any other, from this software.
8+
9+
(ns cljs.lite-collections-test
10+
(:require [cljs.test :refer-macros [deftest testing is are run-tests]]
11+
[clojure.test.check.clojure-test :refer-macros [defspec]]))

src/test/cljs/lite_test_runner.cljs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
;; Copyright (c) Rich Hickey. All rights reserved.
2+
;; The use and distribution terms for this software are covered by the
3+
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+
;; which can be found in the file epl-v10.html at the root of this distribution.
5+
;; By using this software in any fashion, you are agreeing to be bound by
6+
;; the terms of this license.
7+
;; You must not remove this notice, or any other, from this software.
8+
9+
(ns lite-test-runner
10+
(:require [cljs.lite-collections-test]))
11+
12+
(set! *print-newline* false)
13+
14+
;; When testing Windows we default to Node.js
15+
(if (exists? js/print)
16+
(set-print-fn! js/print)
17+
(enable-console-print!))
18+
19+
(run-tests
20+
'cljs.collections-test
21+
)

0 commit comments

Comments
 (0)