[Git][ghc/ghc][wip/three-way-merge-sort] add special cases for lists of size <= 1

Jade (@Jade) gitlab at gitlab.haskell.org
Tue Jan 9 16:12:28 UTC 2024



Jade pushed to branch wip/three-way-merge-sort at Glasgow Haskell Compiler / GHC


Commits:
84217161 by Jade at 2024-01-09T17:15:58+01:00
add special cases for lists of size <= 1

- - - - -


1 changed file:

- libraries/base/src/Data/OldList.hs


Changes:

=====================================
libraries/base/src/Data/OldList.hs
=====================================
@@ -1642,7 +1642,13 @@ https://gitlab.haskell.org/ghc/ghc/issues/24280
 -}
 
 sort = sortBy compare
-sortBy cmp = mergeAll . sequences
+
+sortBy _ []  = []
+sortBy _ [x] = [x]
+sortBy cmp ns
+  | [x, y]    <- ns = merge [x] [y]
+  | [x, y, z] <- ns = merge' [x] [y] [z]
+  | otherwise       = mergeAll (sequences ns)
   where
     x `gt` y = x `cmp` y == GT
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8421716180772dc77bc64484a9950e3556224f67

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8421716180772dc77bc64484a9950e3556224f67
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/20240109/671aba65/attachment-0001.html>


More information about the ghc-commits mailing list