Skip to content

Commit

Permalink
dhall: improve Dhall.Map.traverseWithKey performance (#2589)
Browse files Browse the repository at this point in the history
`traverseWithKey` currently calls `fromList`,
which creates a new list of keys (and calls `nubOrd` on it).
this is unnecessary, because a traversal doesn't change the keys.
  • Loading branch information
imuli authored Jun 12, 2024
1 parent aa4cf87 commit 402fedc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dhall/src/Dhall/Map.hs
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ traverseWithKey
:: Ord k => Applicative f => (k -> a -> f b) -> Map k a -> f (Map k b)
traverseWithKey f (Map m Sorted) =
fmap (\m' -> Map m' Sorted) (Data.Map.traverseWithKey f m)
traverseWithKey f m =
fmap fromList (traverse f' (toList m))
traverseWithKey f m@(Map _ ks) =
flip Map ks . Data.Map.fromList <$> traverse f' (toList m)
where
f' (k, a) = fmap ((,) k) (f k a)
{-# INLINABLE traverseWithKey #-}
Expand Down

0 comments on commit 402fedc

Please sign in to comment.