summaryrefslogtreecommitdiff
path: root/libraries/base/Foreign/Marshal/Array.hs
diff options
context:
space:
mode:
authorsimonmar <unknown>2003-10-21 13:27:13 +0000
committersimonmar <unknown>2003-10-21 13:27:13 +0000
commite2b681aa831de3ff4932575d43917f477d0ee4a6 (patch)
tree6a9c68435608d14c94bf053c8b78be56670c030f /libraries/base/Foreign/Marshal/Array.hs
parent41e6e6ffebcae0c5e92b1778d23e0f656a97c4f3 (diff)
downloadhaskell-e2b681aa831de3ff4932575d43917f477d0ee4a6.tar.gz
[project @ 2003-10-21 13:27:13 by simonmar]
Make peekArray0 run in constant stack-space by testing the length of the array first, then calling peekArray (which works backwards from the end so it can be tail-recursive).
Diffstat (limited to 'libraries/base/Foreign/Marshal/Array.hs')
-rw-r--r--libraries/base/Foreign/Marshal/Array.hs10
1 files changed, 3 insertions, 7 deletions
diff --git a/libraries/base/Foreign/Marshal/Array.hs b/libraries/base/Foreign/Marshal/Array.hs
index 002afed62c..45ea878c3e 100644
--- a/libraries/base/Foreign/Marshal/Array.hs
+++ b/libraries/base/Foreign/Marshal/Array.hs
@@ -136,13 +136,9 @@ 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
--