Skip to content
Snippets Groups Projects
Commit 048b5404 authored by Cheng Shao's avatar Cheng Shao :beach:
Browse files

compiler: use fromAscList when applicable

This patch uses fromAscList (with O(n) complexity) instead of fromList
(with O(nlogn) complexity) in certain Binary instances. It's safe to
do so since the corresponding serialization logic is based on toList
(same as toAscList).

(cherry picked from commit 1c8e608a)
parent 70003f90
No related branches found
No related tags found
No related merge requests found
......@@ -946,8 +946,8 @@ instance Binary a => Binary [a] where
-- | This instance doesn't rely on the determinism of the keys' 'Ord' instance,
-- so it works e.g. for 'Name's too.
instance (Binary a, Ord a) => Binary (Set a) where
put_ bh s = put_ bh (Set.toList s)
get bh = Set.fromList <$> get bh
put_ bh s = put_ bh (Set.toAscList s)
get bh = Set.fromAscList <$> get bh
instance Binary a => Binary (NonEmpty a) where
put_ bh = put_ bh . NonEmpty.toList
......@@ -2092,5 +2092,5 @@ source location as part of a larger structure.
--------------------------------------------------------------------------------
instance (Binary v) => Binary (IntMap v) where
put_ bh m = put_ bh (IntMap.toList m)
get bh = IntMap.fromList <$> get bh
put_ bh m = put_ bh (IntMap.toAscList m)
get bh = IntMap.fromAscList <$> get bh
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment