Skip to content

Commit 2b4a937

Browse files
committed
- fix up HashMap issues
1 parent dadba06 commit 2b4a937

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6560,15 +6560,6 @@ reduces them without incurring seq initialization"
65606560
(= (get y (first xkv) never-equiv) (second xkv)))
65616561
x))))))
65626562

6563-
6564-
(defn- scan-array [incr k array]
6565-
(let [len (alength array)]
6566-
(loop [i 0]
6567-
(when (< i len)
6568-
(if (identical? k (aget array i))
6569-
i
6570-
(recur (+ i incr)))))))
6571-
65726563
;; Record Iterator
65736564
(deftype RecordIter [^:mutable i record base-count fields ext-map-iter]
65746565
Object
@@ -12414,6 +12405,14 @@ reduces them without incurring seq initialization"
1241412405
(keyword (.substring k 2 (. k -length)))
1241512406
k))
1241612407

12408+
(defn- scan-array [incr k array]
12409+
(let [len (alength array)]
12410+
(loop [i 0]
12411+
(when (< i len)
12412+
(if (identical? k (aget array i))
12413+
i
12414+
(recur (+ i incr)))))))
12415+
1241712416
(deftype ObjMap [meta keys strobj ^:mutable __hash]
1241812417
IWithMeta
1241912418
(-with-meta [coll meta] (ObjMap. meta keys strobj __hash))
@@ -12560,6 +12559,14 @@ reduces them without incurring seq initialization"
1256012559
(recur (nnext kvs)))
1256112560
(.fromObject ObjMap ks obj)))))
1256212561

12562+
(defn- scan-array-equiv [incr k array]
12563+
(let [len (alength array)]
12564+
(loop [i 0]
12565+
(when (< i len)
12566+
(if (= k (aget array i))
12567+
i
12568+
(recur (+ i incr)))))))
12569+
1256312570
; The keys field is an array of all keys of this map, in no particular
1256412571
; order. Each key is hashed and the result used as a property name of
1256512572
; hashobj. Each values in hashobj is actually a bucket in order to handle hash
@@ -12611,42 +12618,44 @@ reduces them without incurring seq initialization"
1261112618
ILookup
1261212619
(-lookup [coll k] (-lookup coll k nil))
1261312620
(-lookup [coll k not-found]
12614-
(let [bucket (aget hashobj (hash k))
12615-
i (when bucket (scan-array 2 k bucket))]
12616-
(if i
12621+
(let [bucket (unchecked-get hashobj (hash k))
12622+
i (when bucket (scan-array-equiv 2 k bucket))]
12623+
(if (some? i)
1261712624
(aget bucket (inc i))
1261812625
not-found)))
1261912626

1262012627
IAssociative
1262112628
(-assoc [coll k v]
1262212629
(let [h (hash k)
12623-
bucket (aget hashobj h)]
12630+
bucket (unchecked-get hashobj h)]
1262412631
(if bucket
1262512632
(let [new-bucket (aclone bucket)
1262612633
new-hashobj (gobject/clone hashobj)]
1262712634
(aset new-hashobj h new-bucket)
12628-
(if-let [i (scan-array 2 k new-bucket)]
12629-
(do ; found key, replace
12635+
(if-let [i (scan-array-equiv 2 k new-bucket)]
12636+
(do
12637+
; found key, replace
1263012638
(aset new-bucket (inc i) v)
1263112639
(HashMap. meta count new-hashobj nil))
12632-
(do ; did not find key, append
12640+
(do
12641+
; did not find key, append
1263312642
(.push new-bucket k v)
1263412643
(HashMap. meta (inc count) new-hashobj nil))))
1263512644
(let [new-hashobj (gobject/clone hashobj)] ; did not find bucket
1263612645
(unchecked-set new-hashobj h (array k v))
1263712646
(HashMap. meta (inc count) new-hashobj nil)))))
1263812647
(-contains-key? [coll k]
1263912648
(let [bucket (unchecked-get hashobj (hash k))
12640-
i (when bucket (scan-array 2 k bucket))]
12641-
(if i
12649+
i (when bucket (scan-array-equiv 2 k bucket))]
12650+
(if (some? i)
1264212651
true
1264312652
false)))
1264412653

1264512654
IMap
1264612655
(-dissoc [coll k]
1264712656
(let [h (hash k)
1264812657
bucket (unchecked-get hashobj h)
12649-
i (when bucket (scan-array 2 k bucket))]
12658+
i (when bucket (scan-array-equiv 2 k bucket))]
1265012659
(if (not i)
1265112660
coll ; key not found, return coll unchanged
1265212661
(let [new-hashobj (gobject/clone hashobj)]

0 commit comments

Comments
 (0)