Skip to content

Commit 91e8ee4

Browse files
committed
* update hash to handle bigint
* make number and bigint -equiv * handle bigint & number in PAM * minor refactor of private PAM lookup helper fn names
1 parent 5477284 commit 91e8ee4

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

src/main/cljs/cljs/core.cljs

+43-10
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,10 @@
10121012
h
10131013
(add-to-string-hash-cache k)))))
10141014

1015+
(defn- safe-value? [n]
1016+
(and (<= n js/Number.MAX_SAFE_INTEGER)
1017+
(>= n js/Number.MIN_SAFE_INTEGER)))
1018+
10151019
(defn hash
10161020
"Returns the hash code of its argument. Note this is the hash code
10171021
consistent with =."
@@ -1020,6 +1024,11 @@
10201024
(implements? IHash o)
10211025
(bit-xor (-hash o) 0)
10221026

1027+
(cljs.core/bigint? o)
1028+
(if (safe-value? o)
1029+
(hash (js/Number. o))
1030+
(hash-string (.toString o 32)))
1031+
10231032
(number? o)
10241033
(if ^boolean (js/isFinite o)
10251034
(js-mod (Math/floor o) 2147483647)
@@ -1434,7 +1443,17 @@
14341443

14351444
(extend-type number
14361445
IEquiv
1437-
(-equiv [x o] (identical? x o)))
1446+
(-equiv [x o]
1447+
(if (cljs.core/bigint? o)
1448+
(cljs.core/coercive-= x o)
1449+
(identical? x o))))
1450+
1451+
(extend-type bigint
1452+
IEquiv
1453+
(-equiv [x o]
1454+
(if (cljs.core/js-number? o)
1455+
(cljs.core/coercive-= x o)
1456+
(identical? x o))))
14381457

14391458
(declare with-meta)
14401459

@@ -6687,15 +6706,15 @@ reduces them without incurring seq initialization"
66876706

66886707
;;; PersistentArrayMap
66896708

6690-
(defn- array-index-of-nil? [arr]
6709+
(defn- array-index-of-nil [arr]
66916710
(let [len (alength arr)]
66926711
(loop [i 0]
66936712
(cond
66946713
(<= len i) -1
66956714
(nil? (aget arr i)) i
66966715
:else (recur (+ i 2))))))
66976716

6698-
(defn- array-index-of-keyword? [arr k]
6717+
(defn- array-index-of-keyword [arr k]
66996718
(let [len (alength arr)
67006719
kstr (.-fqn k)]
67016720
(loop [i 0]
@@ -6705,7 +6724,7 @@ reduces them without incurring seq initialization"
67056724
(identical? kstr (.-fqn (aget arr i)))) i
67066725
:else (recur (+ i 2))))))
67076726

6708-
(defn- array-index-of-symbol? [arr k]
6727+
(defn- array-index-of-symbol [arr k]
67096728
(let [len (alength arr)
67106729
kstr (.-str k)]
67116730
(loop [i 0]
@@ -6715,6 +6734,17 @@ reduces them without incurring seq initialization"
67156734
(identical? kstr (.-str (aget arr i)))) i
67166735
:else (recur (+ i 2))))))
67176736

6737+
(defn- equal-number? [x y]
6738+
(and (number? x) (number? y) (cljs.core/coercive-= x y)))
6739+
6740+
(defn- array-index-of-number [arr k]
6741+
(let [len (alength arr)]
6742+
(loop [i 0]
6743+
(cond
6744+
(<= len i) -1
6745+
(equal-number? k (aget arr i)) i
6746+
:else (recur (+ i 2))))))
6747+
67186748
(defn- array-index-of-identical? [arr k]
67196749
(let [len (alength arr)]
67206750
(loop [i 0]
@@ -6723,7 +6753,7 @@ reduces them without incurring seq initialization"
67236753
(identical? k (aget arr i)) i
67246754
:else (recur (+ i 2))))))
67256755

6726-
(defn- array-index-of-equiv? [arr k]
6756+
(defn- array-index-of-equiv [arr k]
67276757
(let [len (alength arr)]
67286758
(loop [i 0]
67296759
(cond
@@ -6733,17 +6763,20 @@ reduces them without incurring seq initialization"
67336763

67346764
(defn array-index-of [arr k]
67356765
(cond
6736-
(keyword? k) (array-index-of-keyword? arr k)
6766+
(keyword? k) (array-index-of-keyword arr k)
67376767

6738-
(or (string? k) (number? k))
6768+
(string? k)
67396769
(array-index-of-identical? arr k)
67406770

6741-
(symbol? k) (array-index-of-symbol? arr k)
6771+
(number? k)
6772+
(array-index-of-number arr k)
6773+
6774+
(symbol? k) (array-index-of-symbol arr k)
67426775

67436776
(nil? k)
6744-
(array-index-of-nil? arr)
6777+
(array-index-of-nil arr)
67456778

6746-
:else (array-index-of-equiv? arr k)))
6779+
:else (array-index-of-equiv arr k)))
67476780

67486781
(defn- array-map-index-of [m k]
67496782
(array-index-of (.-arr m) k))

0 commit comments

Comments
 (0)