From b1803b8ed4865ec4befc448f2c672b13db3b4543 Mon Sep 17 00:00:00 2001 From: David Feuer Date: Tue, 13 Jun 2017 14:45:38 -0400 Subject: [PATCH] Streamline keys and elems Make sure `keys` and `elems` won't build silly pairs and thunks to deconstruct them. --- Data/HashMap/Base.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Data/HashMap/Base.hs b/Data/HashMap/Base.hs index 681b11de..66bd8e97 100644 --- a/Data/HashMap/Base.hs +++ b/Data/HashMap/Base.hs @@ -1161,13 +1161,13 @@ filter p = filterWithKey (\_ v -> p v) -- | /O(n)/ Return a list of this map's keys. The list is produced -- lazily. keys :: HashMap k v -> [k] -keys = L.map fst . toList +keys t = build (\ c z -> foldrWithKey (\ k _v ks -> c k ks) z t) {-# INLINE keys #-} -- | /O(n)/ Return a list of this map's values. The list is produced -- lazily. elems :: HashMap k v -> [v] -elems = L.map snd . toList +elems t = build (\ c z -> foldrWithKey (\ _k v vs -> c v vs) z t) {-# INLINE elems #-} ------------------------------------------------------------------------