on master help sign in
Remove unnecessary laziness from builder.

Decreased run-time on the "builder/mappend char" benchmark with 26% and the "builder/mappend text" benchmark with 3%. --HG-- extra : convert_revision : 87214a063b1a706bc2fe7333416f3e88e1f702ad

commit93c0f067bf90eace409062390e0d735eb8842d16 authorJohan Tibell <johan.tibell@gmail.com> dateFri 30 Apr 2010, 13:49 (16 years ago) parent8ee4d15
1 file changed+5−5
Data/Text/Lazy/Builder.hs+5−5
Data/Text/Lazy/Builder.hs+5−5
@@ -156,11 +156,11 @@ flush = Builder $ \ k buf@(Buffer p o u l) ->
156156------------------------------------------------------------------------
157157
158158-- | Sequence an ST operation on the buffer
159−unsafeLiftST :: (forall s. Buffer s -> ST s (Buffer s)) -> Builder
160−unsafeLiftST f = Builder $ \k buf -> inlineInterleaveST $ do
159+withBuffer :: (forall s. Buffer s -> ST s (Buffer s)) -> Builder
160+withBuffer f = Builder $ \k buf -> do
161161 buf' <- f buf
162162 k buf'
163−{-# INLINE unsafeLiftST #-}
163+{-# INLINE withBuffer #-}
164164
165165-- | Get the size of the buffer
166166withSize :: (Int -> Builder) -> Builder
@@ -193,13 +193,13 @@ ensureFree :: Int -> Builder
193193ensureFree n = n `seq` withSize $ \ l ->
194194 if n <= l
195195 then empty
196− else flush `append` unsafeLiftST (const (newBuffer (max n defaultChunkSize)))
196+ else flush `append` withBuffer (const (newBuffer (max n defaultChunkSize)))
197197{-# INLINE ensureFree #-}
198198
199199-- | Ensure that @n@ many elements are available, and then use @f@ to
200200-- write some elements into the memory.
201201writeN :: Int -> (forall s. A.MArray s Word16 -> Int -> ST s ()) -> Builder
202−writeN n f = ensureFree 1 `append` unsafeLiftST (writeNBuffer n f)
202+writeN n f = ensureFree 1 `append` withBuffer (writeNBuffer n f)
203203{-# INLINE writeN #-}
204204
205205writeNBuffer :: Int -> (A.MArray s Word16 -> Int -> ST s ()) -> (Buffer s)