[project @ 1999-02-02 17:37:39 by simonm]
authorsimonm <unknown>
Tue, 2 Feb 1999 17:37:40 +0000 (17:37 +0000)
committersimonm <unknown>
Tue, 2 Feb 1999 17:37:40 +0000 (17:37 +0000)
Optimise take a little.

ghc/lib/std/PrelList.lhs
ghc/lib/std/PrelNumExtra.lhs
ghc/lib/std/Prelude.lhs

index 8773bf2..5e99d90 100644 (file)
@@ -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
index 4ab38ed..7fb14a8 100644 (file)
@@ -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
index 6ba2bd5..60b292e 100644 (file)
@@ -66,7 +66,7 @@ module Prelude (
   ) where
 
 import PrelBase
-import PrelList hiding ( takeUInt )
+import PrelList hiding ( takeUInt_append )
 import PrelRead
 import PrelNum
 import PrelNumExtra