[Git][ghc/ghc][wip/three-way-merge-sort] WIP
Jade (@Jade)
gitlab at gitlab.haskell.org
Sun Apr 28 08:32:30 UTC 2024
Jade pushed to branch wip/three-way-merge-sort at Glasgow Haskell Compiler / GHC
Commits:
1ac6d7a2 by Jade at 2024-04-28T10:37:27+02:00
WIP
- - - - -
1 changed file:
- libraries/ghc-internal/src/GHC/Internal/Data/OldList.hs
Changes:
=====================================
libraries/ghc-internal/src/GHC/Internal/Data/OldList.hs
=====================================
@@ -1645,8 +1645,14 @@ Further improved using a four-way merge, with an additional performance increase
https://gitlab.haskell.org/ghc/ghc/issues/24280
-}
-sort = sortBy compare
-sortBy cmp ns
+{-# INLINEABLE sort #-} -- allows specialization for the ord instance
+sort = actualSort (>)
+
+{-# INLINEABLE sortBy #-}
+sortBy cmp = actualSort (\x y -> cmp x y == GT)
+
+actualSort :: (a -> a -> Bool) -> [a] -> [a]
+actualSort gt ns
| [] <- ns = []
| [a] <- ns = [a]
| [a,b] <- ns = merge [a] [b]
@@ -1654,8 +1660,6 @@ sortBy cmp ns
| [a,b,c,d] <- ns = merge4 [a] [b] [c] [d]
| otherwise = merge_all (sequences ns)
where
- x `gt` y = x `cmp` y == GT
-
sequences (a:b:xs)
| a `gt` b = descending b [a] xs
| otherwise = ascending b (a:) xs
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1ac6d7a2c60118e25373cd78413ec887c212d2a7
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1ac6d7a2c60118e25373cd78413ec887c212d2a7
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240428/00cd3e32/attachment-0001.html>
More information about the ghc-commits
mailing list