[project @ 2003-10-21 13:27:13 by simonmar]
[ghc-base.git] / Foreign / Marshal / Array.hs
index d8cce25..45ea878 100644 (file)
@@ -62,7 +62,7 @@ module Foreign.Marshal.Array (
 import Control.Monad
 import Foreign.Ptr     (Ptr, plusPtr)
 import Foreign.Storable        (Storable(sizeOf,peekElemOff,pokeElemOff))
-import Foreign.Marshal.Alloc (alloca, mallocBytes, allocaBytes, reallocBytes)
+import Foreign.Marshal.Alloc (mallocBytes, allocaBytes, reallocBytes)
 import Foreign.Marshal.Utils (copyBytes, moveBytes)
 
 #ifdef __GLASGOW_HASKELL__
@@ -136,19 +136,15 @@ peekArray size ptr | size <= 0 = return []
 -- |Convert an array terminated by the given end marker into a Haskell list
 --
 peekArray0            :: (Storable a, Eq a) => a -> Ptr a -> IO [a]
-peekArray0 marker ptr  = loop 0
-  where
-    loop i = do
-        val <- peekElemOff ptr i
-        if val == marker then return [] else do
-            rest <- loop (i+1)
-            return (val:rest)
+peekArray0 marker ptr  = do
+  size <- lengthArray0 marker ptr
+  peekArray size ptr
 
 -- |Write the list elements consecutive into memory
 --
 pokeArray :: Storable a => Ptr a -> [a] -> IO ()
 #ifndef __GLASGOW_HASKELL__
-pokeArray ptrs vals =  zipWithM_ (pokeElemOff ptr) [0..] vals
+pokeArray ptr vals =  zipWithM_ (pokeElemOff ptr) [0..] vals
 #else
 pokeArray ptr vals = go vals 0#
   where go [] n#         = return ()