Skip to content

Commit 6a0fed1

Browse files
authored
two: Avoid branch in computation of idx2 (#469)
1 parent 8c20f7a commit 6a0fed1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Data/HashMap/Internal.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,15 @@ two = go
982982
where
983983
bp1 = mask h1 s
984984
bp2 = mask h2 s
985-
idx2 | index h1 s < index h2 s = 1
986-
| otherwise = 0
985+
!(I# i1) = index h1 s
986+
!(I# i2) = index h2 s
987+
idx2 = I# (i1 Exts.<# i2)
988+
-- This way of computing idx2 saves us a branch compared to the previous approach:
989+
--
990+
-- idx2 | index h1 s < index h2 s = 1
991+
-- | otherwise = 0
992+
--
993+
-- See https://github.com/haskell-unordered-containers/unordered-containers/issues/75#issuecomment-1128419337
987994
{-# INLINE two #-}
988995

989996
-- | \(O(\log n)\) Associate the value with the key in this map. If

0 commit comments

Comments
 (0)