Commit 9c7a7ae8 authored by simonm's avatar simonm

[project @ 1999-02-02 17:37:39 by simonm]

Optimise take a little.
parent 16eb5dec
......@@ -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
......
......@@ -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
......
......@@ -66,7 +66,7 @@ module Prelude (
) where
import PrelBase
import PrelList hiding ( takeUInt )
import PrelList hiding ( takeUInt_append )
import PrelRead
import PrelNum
import PrelNumExtra
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment