From 9c7a7ae8cc042819e0484621e6b93c61fe94b800 Mon Sep 17 00:00:00 2001 From: simonm Date: Tue, 2 Feb 1999 17:37:40 +0000 Subject: [PATCH] [project @ 1999-02-02 17:37:39 by simonm] Optimise take a little. --- ghc/lib/std/PrelList.lhs | 30 +++++++++++++++++++++--------- ghc/lib/std/PrelNumExtra.lhs | 2 +- ghc/lib/std/Prelude.lhs | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ghc/lib/std/PrelList.lhs b/ghc/lib/std/PrelList.lhs index 8773bf2..5e99d90 100644 --- a/ghc/lib/std/PrelList.lhs +++ b/ghc/lib/std/PrelList.lhs @@ -24,7 +24,7 @@ module PrelList ( -- non-standard, but hidden when creating the Prelude -- export list. - takeUInt + takeUInt_append ) where @@ -205,23 +205,35 @@ splitAt _ _ = errorNegativeIdx "splitAt" #else /* hack away */ take :: Int -> [b] -> [b] -take (I# n#) xs = takeUInt n# xs [] +take (I# n#) xs = takeUInt n# xs -- The general code for take, below, checks n <= maxInt -- No need to check for maxInt overflow when specialised -- at type Int or Int# since the Int must be <= maxInt -takeUInt :: Int# -> [b] -> [b] -> [b] -takeUInt n xs rs - | n >=# 0# = take_unsafe_UInt n xs rs +takeUInt :: Int# -> [b] -> [b] +takeUInt n xs + | n >=# 0# = take_unsafe_UInt n xs | otherwise = errorNegativeIdx "take" -take_unsafe_UInt :: Int# -> [b] -> [b] -> [b] -take_unsafe_UInt 0# _ rs = rs -take_unsafe_UInt m ls rs = +take_unsafe_UInt :: Int# -> [b] -> [b] +take_unsafe_UInt 0# _ = [] +take_unsafe_UInt m ls = + case ls of + [] -> [] + (x:xs) -> x : take_unsafe_UInt (m -# 1#) xs + +takeUInt_append :: Int# -> [b] -> [b] -> [b] +takeUInt_append n xs rs + | n >=# 0# = take_unsafe_UInt_append n xs rs + | otherwise = errorNegativeIdx "take" + +take_unsafe_UInt_append :: Int# -> [b] -> [b] -> [b] +take_unsafe_UInt_append 0# _ rs = rs +take_unsafe_UInt_append m ls rs = case ls of [] -> rs - (x:xs) -> x : take_unsafe_UInt (m -# 1#) xs rs + (x:xs) -> x : take_unsafe_UInt_append (m -# 1#) xs rs drop :: Int -> [b] -> [b] drop (I# n#) ls diff --git a/ghc/lib/std/PrelNumExtra.lhs b/ghc/lib/std/PrelNumExtra.lhs index 4ab38ed..7fb14a8 100644 --- a/ghc/lib/std/PrelNumExtra.lhs +++ b/ghc/lib/std/PrelNumExtra.lhs @@ -551,7 +551,7 @@ prR n r e0 s@(h:t) = show ((round (r * 10^n))::Integer) e = e0+1 - takeN (I# n#) ls rs = takeUInt n# ls rs + takeN (I# n#) ls rs = takeUInt_append n# ls rs drop0 :: String -> String -> String drop0 [] rs = rs diff --git a/ghc/lib/std/Prelude.lhs b/ghc/lib/std/Prelude.lhs index 6ba2bd5..60b292e 100644 --- a/ghc/lib/std/Prelude.lhs +++ b/ghc/lib/std/Prelude.lhs @@ -66,7 +66,7 @@ module Prelude ( ) where import PrelBase -import PrelList hiding ( takeUInt ) +import PrelList hiding ( takeUInt_append ) import PrelRead import PrelNum import PrelNumExtra -- 1.7.10.4