diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2023-02-27 21:38:21 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-03-01 04:17:56 -0500 |
commit | a2a1a1c08bb520b74b00194a83add82b287b38d5 (patch) | |
tree | efc959b19d4229b4eb04c990fe80947962ff6198 /libraries | |
parent | 79ffa170a6b0b152da0e02744869311773733286 (diff) | |
download | haskell-a2a1a1c08bb520b74b00194a83add82b287b38d5.tar.gz |
Revert the main payload of "Make `drop` and `dropWhile` fuse (#18964)"
This reverts the bits affecting fusion of `drop` and `dropWhile` of commit
0f7588b5df1fc7a58d8202761bf1501447e48914 and keeps just the small refactoring
unifying `flipSeqTake` and `flipSeqScanl'` into `flipSeq`.
It also adds a new test for #23021 (which was the reason for reverting) as
well as adds a clarifying comment to T18964.
Fixes #23021, unfixes #18964.
Metric Increase:
T18964
Metric Decrease:
T18964
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/GHC/List.hs | 41 |
1 files changed, 8 insertions, 33 deletions
diff --git a/libraries/base/GHC/List.hs b/libraries/base/GHC/List.hs index 4427d1af1b..d88112f0f3 100644 --- a/libraries/base/GHC/List.hs +++ b/libraries/base/GHC/List.hs @@ -886,23 +886,12 @@ takeWhileFB p c n = \x r -> if p x then x `c` r else n -- [] -- >>> dropWhile (< 0) [1,2,3] -- [1,2,3] -{-# NOINLINE [1] dropWhile #-} dropWhile :: (a -> Bool) -> [a] -> [a] dropWhile _ [] = [] dropWhile p xs@(x:xs') | p x = dropWhile p xs' | otherwise = xs -{-# INLINE [0] dropWhileFB #-} -- See Note [Inline FB functions] -dropWhileFB :: (a -> Bool) -> (a -> b -> b) -> b -> a -> (Bool -> b) -> Bool -> b -dropWhileFB p c _n x xs = \drp -> if drp && p x then xs True else x `c` xs False - -{-# RULES -"dropWhile" [~1] forall p xs. dropWhile p xs = - build (\c n -> foldr (dropWhileFB p c n) (flipSeq n) xs True) -"dropWhileList" [1] forall p xs. foldr (dropWhileFB p (:) []) (flipSeq []) xs True = dropWhile p xs - #-} - -- | 'take' @n@, applied to a list @xs@, returns the prefix of @xs@ -- of length @n@, or @xs@ itself if @n >= 'length' xs@. -- @@ -998,31 +987,17 @@ drop n xs | n <= 0 = xs drop _ [] = [] drop n (_:xs) = drop (n-1) xs #else /* hack away */ -{-# INLINE[1] drop #-} -- Why [1]? See justification on take! => RULES +{-# INLINE drop #-} drop n ls | n <= 0 = ls | otherwise = unsafeDrop n ls - --- A version of drop that drops the whole list if given an argument --- less than 1 -{-# NOINLINE [0] unsafeDrop #-} -- See Note [Inline FB functions] -unsafeDrop :: Int -> [a] -> [a] -unsafeDrop !_ [] = [] -unsafeDrop 1 (_:xs) = xs -unsafeDrop m (_:xs) = unsafeDrop (m - 1) xs - -{-# RULES -"drop" [~1] forall n xs . drop n xs = - build (\c nil -> if n <= 0 - then foldr c nil xs - else foldr (dropFB c nil) (flipSeq nil) xs n) -"unsafeDropList" [1] forall n xs . foldr (dropFB (:) []) (flipSeq []) xs n - = unsafeDrop n xs - #-} - -{-# INLINE [0] dropFB #-} -- See Note [Inline FB functions] -dropFB :: (a -> b -> b) -> b -> a -> (Int -> b) -> Int -> b -dropFB c _n x xs = \ m -> if m <= 0 then x `c` xs m else xs (m-1) + where + -- A version of drop that drops the whole list if given an argument + -- less than 1 + unsafeDrop :: Int -> [a] -> [a] + unsafeDrop !_ [] = [] + unsafeDrop 1 (_:xs) = xs + unsafeDrop m (_:xs) = unsafeDrop (m - 1) xs #endif -- | 'splitAt' @n xs@ returns a tuple where first element is @xs@ prefix of |