File tree Expand file tree Collapse file tree 3 files changed +7
-17
lines changed
Expand file tree Collapse file tree 3 files changed +7
-17
lines changed Original file line number Diff line number Diff line change @@ -1273,7 +1273,7 @@ update f = Exts.inline alter (>>= f)
12731273-- 'lookup' k ('alter' f k m) = f ('lookup' k m)
12741274-- @
12751275alter :: (Eq k , Hashable k ) => (Maybe v -> Maybe v ) -> k -> HashMap k v -> HashMap k v
1276- alter f k = alter' f (hash k) k
1276+ alter f k = Exts. inline alter' f (hash k) k
12771277{-# INLINABLE alter #-}
12781278
12791279alter' :: Eq k => (Maybe v -> Maybe v ) -> Hash -> k -> HashMap k v -> HashMap k v
Original file line number Diff line number Diff line change @@ -299,7 +299,7 @@ adjust f k0 m0 = go h0 k0 0 m0
299299-- (if it is in the map). If @(f x)@ is 'Nothing', the element is deleted.
300300-- If it is @('Just' y)@, the key @k@ is bound to the new value @y@.
301301update :: (Eq k , Hashable k ) => (a -> Maybe a ) -> k -> HashMap k a -> HashMap k a
302- update f = alter (>>= f)
302+ update f = Exts. inline alter (>>= f)
303303{-# INLINABLE update #-}
304304
305305-- | \(O(\log n)\) The expression @('alter' f k map)@ alters the value @x@ at @k@, or
@@ -311,19 +311,9 @@ update f = alter (>>= f)
311311-- 'lookup' k ('alter' f k m) = f ('lookup' k m)
312312-- @
313313alter :: (Eq k , Hashable k ) => (Maybe v -> Maybe v ) -> k -> HashMap k v -> HashMap k v
314- alter f k m =
315- let ! h = hash k
316- ! lookupRes = HM. lookupRecordCollision h k m
317- in case f (HM. lookupResToMaybe lookupRes) of
318- Nothing -> case lookupRes of
319- Absent -> m
320- Present _ collPos -> HM. deleteKeyExists collPos h k m
321- Just ! v' -> case lookupRes of
322- Absent -> HM. insertNewKey h k v' m
323- Present v collPos ->
324- if v `ptrEq` v'
325- then m
326- else HM. insertKeyExists collPos h k v' m
314+ alter f = Exts. inline HM. alter $ \ m -> case f m of
315+ Nothing -> Nothing
316+ Just ! x -> Just x
327317{-# INLINABLE alter #-}
328318
329319-- | \(O(\log n)\) The expression (@'alterF' f k map@) alters the value @x@ at
Original file line number Diff line number Diff line change @@ -69,8 +69,8 @@ library
6969 MagicHash,
7070 BangPatterns
7171
72- -- ghc-options: -Wall -O2 -fwarn-tabs -ferror-spans
73- ghc-options : -Wall -fwarn-tabs -ferror-spans
72+ ghc-options : -Wall -O2 -fwarn-tabs -ferror-spans
73+ -- ghc-options: -Wall -fwarn-tabs -ferror-spans
7474
7575 -- For dumping the generated code:
7676 -- ghc-options: -ddump-simpl -ddump-stg-final -ddump-cmm -ddump-asm -ddump-to-file
You can’t perform that action at this time.
0 commit comments