|
548 | 548 |
|
549 | 549 | (defprotocol IFind |
550 | 550 | "Protocol for implementing entry finding in collections." |
551 | | - (-find [coll k])) |
| 551 | + (-find [coll k] "Returns the map entry for key, or nil if key not present.")) |
552 | 552 |
|
553 | 553 | (defprotocol IMap |
554 | 554 | "Protocol for adding mapping functionality to collections." |
@@ -2242,11 +2242,11 @@ reduces them without incurring seq initialization" |
2242 | 2242 | (defn find |
2243 | 2243 | "Returns the map entry for key, or nil if key not present." |
2244 | 2244 | [coll k] |
2245 | | - (when (and (not (nil? coll)) |
2246 | | - (associative? coll) |
2247 | | - (contains? coll k)) |
2248 | | - (if (ifind? coll) |
2249 | | - (-find coll k) |
| 2245 | + (if (ifind? coll) |
| 2246 | + (-find coll k) |
| 2247 | + (when (and (not (nil? coll)) |
| 2248 | + (associative? coll) |
| 2249 | + (contains? coll k)) |
2250 | 2250 | [k (get coll k)]))) |
2251 | 2251 |
|
2252 | 2252 | (defn ^boolean distinct? |
@@ -5231,8 +5231,9 @@ reduces them without incurring seq initialization" |
5231 | 5231 | false)) |
5232 | 5232 |
|
5233 | 5233 | IFind |
5234 | | - (-find [coll k] |
5235 | | - [k (get coll k)]) |
| 5234 | + (-find [coll n] |
| 5235 | + (when (and (== n (bit-or n 0)) (<= 0 n) (< n cnt)) |
| 5236 | + [n (aget (unchecked-array-for coll n) (bit-and n 0x01f))])) |
5236 | 5237 |
|
5237 | 5238 | APersistentVector |
5238 | 5239 | IVector |
@@ -5522,8 +5523,9 @@ reduces them without incurring seq initialization" |
5522 | 5523 | (throw (js/Error. "Subvec's key for assoc must be a number.")))) |
5523 | 5524 |
|
5524 | 5525 | IFind |
5525 | | - (-find [coll key] |
5526 | | - [key (get coll key)]) |
| 5526 | + (-find [coll n] |
| 5527 | + (when (<= end (+ start n)) |
| 5528 | + (-find v (+ start n)))) |
5527 | 5529 |
|
5528 | 5530 | IVector |
5529 | 5531 | (-assoc-n [coll n val] |
@@ -6060,7 +6062,9 @@ reduces them without incurring seq initialization" |
6060 | 6062 |
|
6061 | 6063 | IFind |
6062 | 6064 | (-find [coll k] |
6063 | | - [k (get coll k)]) |
| 6065 | + (when (and ^boolean (goog/isString k) |
| 6066 | + (not (nil? (scan-array 1 k keys)))) |
| 6067 | + [k (aget strobj k)])) |
6064 | 6068 |
|
6065 | 6069 | IKVReduce |
6066 | 6070 | (-kv-reduce [coll f init] |
@@ -6289,10 +6293,10 @@ reduces them without incurring seq initialization" |
6289 | 6293 |
|
6290 | 6294 | IFind |
6291 | 6295 | (-find [node k] |
6292 | | - (cond |
6293 | | - (== k 0) [0 key] |
6294 | | - (== k 1) [1 val] |
6295 | | - :else nil)) |
| 6296 | + (case k |
| 6297 | + 0 [0 key] |
| 6298 | + 1 [1 val] |
| 6299 | + nil)) |
6296 | 6300 |
|
6297 | 6301 | IVector |
6298 | 6302 | (-assoc-n [node n v] |
@@ -6505,7 +6509,8 @@ reduces them without incurring seq initialization" |
6505 | 6509 | IFind |
6506 | 6510 | (-find [coll k] |
6507 | 6511 | (let [idx (array-map-index-of coll k)] |
6508 | | - [(aget arr idx) (get coll k)])) |
| 6512 | + (when-not (== idx -1) |
| 6513 | + [(aget arr idx) (aget arr (inc idx))]))) |
6509 | 6514 |
|
6510 | 6515 | IMap |
6511 | 6516 | (-dissoc [coll k] |
@@ -7949,10 +7954,10 @@ reduces them without incurring seq initialization" |
7949 | 7954 |
|
7950 | 7955 | IFind |
7951 | 7956 | (-find [node k] |
7952 | | - (cond |
7953 | | - (== k 0) [0 key] |
7954 | | - (== k 1) [1 val] |
7955 | | - :else nil)) |
| 7957 | + (case k |
| 7958 | + 0 [0 key] |
| 7959 | + 1 [1 val] |
| 7960 | + nil)) |
7956 | 7961 |
|
7957 | 7962 | IVector |
7958 | 7963 | (-assoc-n [node n v] |
@@ -8110,10 +8115,10 @@ reduces them without incurring seq initialization" |
8110 | 8115 |
|
8111 | 8116 | IFind |
8112 | 8117 | (-find [node k] |
8113 | | - (cond |
8114 | | - (== k 0) [0 key] |
8115 | | - (== k 1) [1 val] |
8116 | | - :else nil)) |
| 8118 | + (case k |
| 8119 | + 0 [0 key] |
| 8120 | + 1 [1 val] |
| 8121 | + nil)) |
8117 | 8122 |
|
8118 | 8123 | IVector |
8119 | 8124 | (-assoc-n [node n v] |
|
0 commit comments