summaryrefslogtreecommitdiff
path: root/ghc/compiler/utils
diff options
context:
space:
mode:
authorsimonmar <unknown>2005-07-28 12:57:13 +0000
committersimonmar <unknown>2005-07-28 12:57:13 +0000
commitb64b016b9f2b095f4c449e878f41483d754fb8dc (patch)
tree94cb3a3cc9afe603c2cdb3d1f0e16a3ce513295d /ghc/compiler/utils
parent52ed73913693626b505287178c20f05913d00a07 (diff)
downloadhaskell-b64b016b9f2b095f4c449e878f41483d754fb8dc.tar.gz
[project @ 2005-07-28 12:57:13 by simonmar]
optimise instance for lists: now we record the length first followed by the elements. HEADS UP: changes interface file representation, rebuild your libraries.
Diffstat (limited to 'ghc/compiler/utils')
-rw-r--r--ghc/compiler/utils/Binary.hs22
1 files changed, 14 insertions, 8 deletions
diff --git a/ghc/compiler/utils/Binary.hs b/ghc/compiler/utils/Binary.hs
index c20e2aa22b..1902ff1f66 100644
--- a/ghc/compiler/utils/Binary.hs
+++ b/ghc/compiler/utils/Binary.hs
@@ -458,14 +458,20 @@ instance Binary Int where
-- getF bh = getBitsF bh 32
instance Binary a => Binary [a] where
- put_ bh [] = putByte bh 0
- put_ bh (x:xs) = do putByte bh 1; put_ bh x; put_ bh xs
- get bh = do h <- getWord8 bh
- case h of
- 0 -> return []
- _ -> do x <- get bh
- xs <- get bh
- return (x:xs)
+ put_ bh l = do
+ let len = length l
+ if (len < 0xff)
+ then putByte bh (fromIntegral len :: Word8)
+ else do putByte bh 0xff; put_ bh (fromIntegral len :: Word32)
+ mapM_ (put_ bh) l
+ get bh = do
+ b <- getByte bh
+ len <- if b == 0xff
+ then get bh
+ else return (fromIntegral b :: Word32)
+ let loop 0 = return []
+ loop n = do a <- get bh; as <- loop (n-1); return (a:as)
+ loop len
instance (Binary a, Binary b) => Binary (a,b) where
put_ bh (a,b) = do put_ bh a; put_ bh b