X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Foreign%2FMarshal%2FArray.hs;h=45ea878c3ef9aa9d0bbee43c7157e6aaaeda8556;hb=a0527fc18dd66c1b6bef7d7e9f5bd7d1af51394a;hp=d8cce25922468878e5173431c7633b777b0a742e;hpb=3d08340bbc85f896df252957b36cc2153598680b;p=ghc-base.git diff --git a/Foreign/Marshal/Array.hs b/Foreign/Marshal/Array.hs index d8cce25..45ea878 100644 --- a/Foreign/Marshal/Array.hs +++ b/Foreign/Marshal/Array.hs @@ -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 ()