@@ -1026,11 +1026,11 @@ insertModifyingArr x f k0 ary0 = go k0 ary0 0 (A.length ary0)
1026
1026
unsafeInsertWith :: forall k v . (Eq k , Hashable k )
1027
1027
=> (v -> v -> v ) -> k -> v -> HashMap k v
1028
1028
-> HashMap k v
1029
- unsafeInsertWith f k0 v0 m0 = unsafeInsertWithKey (const f ) k0 v0 m0
1029
+ unsafeInsertWith f k0 v0 m0 = unsafeInsertWithKey (\ _ a b -> ( # f a b # ) ) k0 v0 m0
1030
1030
{-# INLINABLE unsafeInsertWith #-}
1031
1031
1032
1032
unsafeInsertWithKey :: forall k v . (Eq k , Hashable k )
1033
- => (k -> v -> v -> v ) -> k -> v -> HashMap k v
1033
+ => (k -> v -> v -> ( # v # ) ) -> k -> v -> HashMap k v
1034
1034
-> HashMap k v
1035
1035
unsafeInsertWithKey f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
1036
1036
where
@@ -1039,7 +1039,8 @@ unsafeInsertWithKey f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
1039
1039
go ! h ! k x ! _ Empty = return $! Leaf h (L k x)
1040
1040
go h k x s t@ (Leaf hy l@ (L ky y))
1041
1041
| hy == h = if ky == k
1042
- then return $! Leaf h (L k (f k x y))
1042
+ then case f k x y of
1043
+ (# v # ) -> return $! Leaf h (L k v)
1043
1044
else return $! collision h l (L k x)
1044
1045
| otherwise = two s h k x hy t
1045
1046
go h k x s t@ (BitmapIndexed b ary)
@@ -1060,7 +1061,7 @@ unsafeInsertWithKey f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
1060
1061
return t
1061
1062
where i = index h s
1062
1063
go h k x s t@ (Collision hy v)
1063
- | h == hy = return $! Collision h (updateOrSnocWithKey ( \ key a b -> ( # f key a b # ) ) k x v)
1064
+ | h == hy = return $! Collision h (updateOrSnocWithKey f k x v)
1064
1065
| otherwise = go h k x s $ BitmapIndexed (mask hy s) (A. singleton t)
1065
1066
{-# INLINABLE unsafeInsertWithKey #-}
1066
1067
@@ -2104,7 +2105,7 @@ fromListWith f = List.foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty
2104
2105
--
2105
2106
-- @since 0.2.11
2106
2107
fromListWithKey :: (Eq k , Hashable k ) => (k -> v -> v -> v ) -> [(k , v )] -> HashMap k v
2107
- fromListWithKey f = List. foldl' (\ m (k, v) -> unsafeInsertWithKey f k v m) empty
2108
+ fromListWithKey f = List. foldl' (\ m (k, v) -> unsafeInsertWithKey ( \ k' a b -> ( # f k' a b # )) k v m) empty
2108
2109
{-# INLINE fromListWithKey #-}
2109
2110
2110
2111
------------------------------------------------------------------------
0 commit comments