Skip to content

Commit

Permalink
Remove redundant key comparisons in HashCollisionNode
Browse files Browse the repository at this point in the history
Comparing key to array[idx] is redundant as findIndex already performed
key comparison to find the index.

clojure/clojure@8b4261b
  • Loading branch information
frenchy64 committed Aug 23, 2024
1 parent fa3afbd commit 29e3a00
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/com/ambrosebs/map.clj
Original file line number Diff line number Diff line change
Expand Up @@ -848,29 +848,17 @@

(find-node [this shift hash key]
(let [idx (find-index array count key)]
(cond
(< idx 0)
(if (< idx 0)
nil

(= key (aget array idx))
(MapEntry/create (aget array idx)
(aget array (inc idx)))

:else
nil)))
(aget array (inc idx))))))

(find-node [this shift hash key not-found]
(let [idx (find-index array count key)]
(cond
(< idx 0)
(if (< idx 0)
not-found

(= key (aget array idx))
(MapEntry/create (aget array idx)
(aget array (inc idx)))

:else
not-found)))
(aget array (inc idx))))))

(node-seq [this]
(node-seq-create array))
Expand Down

0 comments on commit 29e3a00

Please sign in to comment.