Skip to content

Commit 9a3553d

Browse files
committed
Use A.index# instead of the removed A.index function
1 parent 5779cc8 commit 9a3553d

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

Data/HashMap/Internal.hs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,52 +1301,51 @@ alter' f h0 k0 m0 = go h0 k0 0 m0
13011301
| b .&. m == 0 = case f Nothing of
13021302
Nothing -> t
13031303
Just v' -> bitmapIndexedOrFull (b .|. m) $! A.insert ary i $! Leaf h $! L k v'
1304-
| otherwise = do
1305-
let !st = A.index ary i
1306-
!st' = go h k (nextShift s) st
1307-
if st' `ptrEq` st
1308-
then t
1309-
else case st' of
1310-
Empty
1311-
| A.length ary == 1 -> Empty
1312-
| A.length ary == 2 ->
1313-
case (i, A.index ary 0, A.index ary 1) of
1314-
(0, _, l) | isLeafOrCollision l -> l
1315-
(1, l, _) | isLeafOrCollision l -> l
1316-
_ -> bIndexed
1317-
| otherwise -> bIndexed
1318-
where
1319-
bIndexed = BitmapIndexed (b .&. complement m) (A.delete ary i)
1320-
l | isLeafOrCollision l && A.length ary == 1 -> l
1321-
_ -> BitmapIndexed b (A.update ary i st')
1304+
| otherwise =
1305+
case A.index# ary i of
1306+
(# !st #) -> do
1307+
let !st' = go h k (nextShift s) st
1308+
if st' `ptrEq` st
1309+
then t
1310+
else case st' of
1311+
Empty
1312+
| A.length ary == 2
1313+
, (# l #) <- A.index# ary (otherOfOneOrZero i)
1314+
, isLeafOrCollision l
1315+
-> l
1316+
| otherwise -> bIndexed
1317+
where
1318+
bIndexed = BitmapIndexed (b .&. complement m) (A.delete ary i)
1319+
l | isLeafOrCollision l && A.length ary == 1 -> l
1320+
_ -> BitmapIndexed b (A.update ary i st')
13221321
where
13231322
m = mask h s
13241323
i = sparseIndex b m
13251324
go h k s t@(Full ary) = do
1326-
let !st = A.index ary i
1327-
!st' = go h k (nextShift s) st
1328-
if st' `ptrEq` st
1329-
then t
1330-
else case st' of
1331-
Empty ->
1332-
let ary' = A.delete ary i
1333-
bm = fullBitmap .&. complement (1 `unsafeShiftL` i)
1334-
in BitmapIndexed bm ary'
1335-
_ -> Full (A.update ary i st')
1336-
where
1337-
i = index h s
1325+
case A.index# ary i of
1326+
(# !st #) -> do
1327+
let !st' = go h k (nextShift s) st
1328+
if st' `ptrEq` st
1329+
then t
1330+
else case st' of
1331+
Empty ->
1332+
let ary' = A.delete ary i
1333+
bm = fullBitmap .&. complement (1 `unsafeShiftL` i)
1334+
in BitmapIndexed bm ary'
1335+
_ -> Full (A.update ary i st')
1336+
where i = index h s
13381337
go h k s t@(Collision hy ls)
13391338
| h == hy = case indexOf k ls of
13401339
Just i -> do
1341-
let !(L _ v) = A.index ls i
1342-
case f $ Just v of
1343-
Nothing
1344-
| A.length ls == 2 ->
1345-
if i == 0
1346-
then Leaf h (A.index ls 1)
1347-
else Leaf h (A.index ls 0)
1348-
| otherwise -> Collision hy (A.delete ls i)
1349-
Just v' -> Collision hy $ A.update ls i $ L k v'
1340+
case A.index# ls i of
1341+
(# L _ v #) ->
1342+
case f $ Just v of
1343+
Nothing
1344+
| A.length ls == 2 ->
1345+
case A.index# ls (otherOfOneOrZero i) of
1346+
(# l #) -> Leaf h l
1347+
| otherwise -> Collision hy (A.delete ls i)
1348+
Just v' -> Collision hy $ A.update ls i $ L k v'
13501349
Nothing -> case f Nothing of
13511350
Nothing -> t
13521351
Just v' -> Collision hy $ A.snoc ls $ L k v'

0 commit comments

Comments
 (0)