From 7902bbcbe01b29c95e603a6e5d5cc29eb2f66802 Mon Sep 17 00:00:00 2001 From: Cheng Shao <terrorjack@type.dance> Date: Mon, 3 Feb 2025 16:15:55 +0000 Subject: [PATCH] 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 1c8e608a84b9d54abb352b59a592d4669872517e) (cherry picked from commit 048b5404bb4cfe93fbe8107cacceab6bbb67d8be) --- compiler/GHC/Utils/Binary.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/GHC/Utils/Binary.hs b/compiler/GHC/Utils/Binary.hs index 2b246f3c66d..30e0574d6ca 100644 --- a/compiler/GHC/Utils/Binary.hs +++ b/compiler/GHC/Utils/Binary.hs @@ -697,8 +697,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 @@ -1540,5 +1540,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 -- GitLab