@@ -97,7 +97,7 @@ singleton c = putChar c
98append :: Builder -> Builder -> Builder
98append :: Builder -> Builder -> Builder
99append (Builder f) (Builder g) = Builder (f . g)
99append (Builder f) (Builder g) = Builder (f . g)
100−{-# INLINE append #-}
100+{-# INLINE [1] append #-}
102-- TODO: Experiment to find the right threshold.
102-- TODO: Experiment to find the right threshold.
103copyLimit :: Int
103copyLimit :: Int
@@ -201,13 +201,13 @@ ensureFree !n = withSize $ \ l ->
201 if n <= l
201 if n <= l
202 then empty
202 then empty
203 else flush `append` withBuffer (const (newBuffer (max n defaultChunkSize)))
203 else flush `append` withBuffer (const (newBuffer (max n defaultChunkSize)))
204−{-# INLINE ensureFree #-}
204+{-# INLINE [1] ensureFree #-}
206-- | Ensure that @n@ many elements are available, and then use @f@ to
206-- | Ensure that @n@ many elements are available, and then use @f@ to
207-- write some elements into the memory.
207-- write some elements into the memory.
208writeN :: Int -> (forall s. A.MArray s Word16 -> Int -> ST s ()) -> Builder
208writeN :: Int -> (forall s. A.MArray s Word16 -> Int -> ST s ()) -> Builder
209writeN n f = ensureFree 1 `append` withBuffer (writeNBuffer n f)
209writeN n f = ensureFree 1 `append` withBuffer (writeNBuffer n f)
210−{-# INLINE writeN #-}
210+{-# INLINE [1] writeN #-}
212writeNBuffer :: Int -> (A.MArray s Word16 -> Int -> ST s ()) -> (Buffer s)
212writeNBuffer :: Int -> (A.MArray s Word16 -> Int -> ST s ()) -> (Buffer s)
213 -> ST s (Buffer s)
213 -> ST s (Buffer s)
@@ -235,3 +235,21 @@ unsafeCopy src sidx dest didx count =
235 | otherwise = do A.unsafeWrite dest j (A.unsafeIndex src i)
235 | otherwise = do A.unsafeWrite dest j (A.unsafeIndex src i)
236 copy_loop (i+1) (j+1) (c+1)
236 copy_loop (i+1) (j+1) (c+1)
237{-# INLINE unsafeCopy #-}
237{-# INLINE unsafeCopy #-}
239+------------------------------------------------------------------------
240+-- Some nice rules for Builder
244+"writeN/combine" forall a b (f::forall s. A.MArray s Word16 -> Int -> ST s ())
245+ (g::forall s. A.MArray s Word16 -> Int -> ST s ()).
246+ append (writeN a f) (writeN b g) =
247+ (writeN (a+b) (\marr o -> f marr o >> g marr (o+a)))
249+"ensureFree/combine" forall a b .
250+ append (ensureFree a) (ensureFree b) = ensureFree (max a b)
253+ append flush flush = flush