From: simonmar Date: Tue, 28 Jan 2003 11:07:39 +0000 (+0000) Subject: [project @ 2003-01-28 11:07:39 by simonmar] X-Git-Tag: nhc98-1-18-release~748 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=3d08340bbc85f896df252957b36cc2153598680b;hp=4e62d8842ce3fb33590bd73da2f4262dbfa37024;p=haskell-directory.git [project @ 2003-01-28 11:07:39 by simonmar] Hand-optimised versions of pokeArray and pokeArray0 (selected via #ifdef __GLASGOW_HASKELL__). I tried to make these functions amenable to deforestation, but couildn't quite get it to work, so in the meantime we'll settle for hand-written versions which are still quite a bit faster than the originals. --- diff --git a/Foreign/Marshal/Array.hs b/Foreign/Marshal/Array.hs index ae7db1a..d8cce25 100644 --- a/Foreign/Marshal/Array.hs +++ b/Foreign/Marshal/Array.hs @@ -146,16 +146,28 @@ peekArray0 marker ptr = loop 0 -- |Write the list elements consecutive into memory -- -pokeArray :: Storable a => Ptr a -> [a] -> IO () -pokeArray ptr vals = zipWithM_ (pokeElemOff ptr) [0..] vals +pokeArray :: Storable a => Ptr a -> [a] -> IO () +#ifndef __GLASGOW_HASKELL__ +pokeArray ptrs vals = zipWithM_ (pokeElemOff ptr) [0..] vals +#else +pokeArray ptr vals = go vals 0# + where go [] n# = return () + go (val:vals) n# = do pokeElemOff ptr (I# n#) val; go vals (n# +# 1#) +#endif -- |Write the list elements consecutive into memory and terminate them with the -- given marker element -- -pokeArray0 :: Storable a => a -> Ptr a -> [a] -> IO () +pokeArray0 :: Storable a => a -> Ptr a -> [a] -> IO () +#ifndef __GLASGOW_HASKELL__ pokeArray0 marker ptr vals = do pokeArray ptr vals pokeElemOff ptr (length vals) marker +#else +pokeArray0 marker ptr vals = go vals 0# + where go [] n# = pokeElemOff ptr (I# n#) marker + go (val:vals) n# = do pokeElemOff ptr (I# n#) val; go vals (n# +# 1#) +#endif -- combined allocation and marshalling