Skip to content

Commit 89c7baa

Browse files
committed
two: Optimize computation of idx2 further
This reduces the core size for the inner loop of two by 10 terms.
1 parent 1029038 commit 89c7baa

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Data/HashMap/Internal.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ import Data.Hashable (Hashable)
164164
import Data.Hashable.Lifted (Hashable1, Hashable2)
165165
import Data.HashMap.Internal.List (isPermutationBy, unorderedCompare)
166166
import Data.Semigroup (Semigroup (..), stimesIdempotentMonoid)
167-
import GHC.Exts (Int (..), Int#, TYPE, (==#))
167+
import GHC.Exts (Int (..), Int#, TYPE, Word (..), (==#))
168168
import GHC.Stack (HasCallStack)
169169
import Prelude hiding (Foldable (..), filter, lookup, map,
170170
pred)
@@ -978,11 +978,9 @@ two = go
978978
ary <- A.unsafeFreeze mary
979979
return $ BitmapIndexed (bp1 .|. bp2) ary
980980
where
981-
bp1 = mask h1 s
982-
bp2 = mask h2 s
983-
!(I# i1) = index h1 s
984-
!(I# i2) = index h2 s
985-
idx2 = I# (i1 Exts.<# i2)
981+
!bp1@(W# bp1#) = mask h1 s
982+
!bp2@(W# bp2#) = mask h2 s
983+
idx2 = I# (bp1# `Exts.ltWord#` bp2#)
986984
-- This way of computing idx2 saves us a branch compared to the previous approach:
987985
--
988986
-- idx2 | index h1 s < index h2 s = 1

0 commit comments

Comments
 (0)