Skip to content

Commit

Permalink
dhall: improve Dhall.Map.traverseWithKey performance
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 committed May 24, 2024
1 parent e281834 commit e01de32
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 e01de32

Please sign in to comment.