Skip to content

Commit 402fedc

Browse files
authored
dhall: improve Dhall.Map.traverseWithKey performance (#2589)
`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.
1 parent aa4cf87 commit 402fedc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

dhall/src/Dhall/Map.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,8 @@ traverseWithKey
623623
:: Ord k => Applicative f => (k -> a -> f b) -> Map k a -> f (Map k b)
624624
traverseWithKey f (Map m Sorted) =
625625
fmap (\m' -> Map m' Sorted) (Data.Map.traverseWithKey f m)
626-
traverseWithKey f m =
627-
fmap fromList (traverse f' (toList m))
626+
traverseWithKey f m@(Map _ ks) =
627+
flip Map ks . Data.Map.fromList <$> traverse f' (toList m)
628628
where
629629
f' (k, a) = fmap ((,) k) (f k a)
630630
{-# INLINABLE traverseWithKey #-}

0 commit comments

Comments
 (0)