git.iko.soy/typeable/attoparsec
on master help sign in
Add a fast mconcat implementation

--HG-- extra : amend_source : c59dceefe105507e69eb1efa193c507bef819b05

commit22c483a88226ee1c22754a122eba510336f7c917 authorBryan O'Sullivan <bos@serpentine.com> dateMon 26 May 2014, 22:43 (12 years ago) parente94e8f6
2 files changed+8
Data/Attoparsec/ByteString/Buffer.hs+4 Data/Attoparsec/Text/Buffer.hs+4
Data/Attoparsec/ByteString/Buffer.hs+4
@@ -34,6 +34,7 @@ module Data.Attoparsec.ByteString.Buffer
3434import Control.Exception (assert)
3535import Data.Attoparsec.ByteString.Fhthagn (inlinePerformIO)
3636import Data.ByteString.Internal (ByteString(..), memcpy, nullForeignPtr)
37+import Data.List (foldl1')
3738import Data.Monoid (Monoid(..))
3839import Data.Word (Word8)
3940import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
@@ -84,6 +85,9 @@ instance Monoid Buffer where
8485 memcpy (ptr `plusPtr` len0) (ptr1 `plusPtr` off1) len1
8586 return (Buf fp 0 newlen newcap)
8687
88+ mconcat [] = mempty
89+ mconcat xs = foldl1' mappend xs
90+
8791length :: Buffer -> Int
8892length (Buf _ _ len _) = len
8993{-# INLINE length #-}
Data/Attoparsec/Text/Buffer.hs+4
@@ -35,6 +35,7 @@ module Data.Attoparsec.Text.Buffer
3535 ) where
3636
3737import Control.Exception (assert)
38+import Data.List (foldl1')
3839import Data.Monoid (Monoid(..))
3940import Data.Text ()
4041import Data.Text.Internal (Text(..))
@@ -86,6 +87,9 @@ instance Monoid Buffer where
8687 arr2 <- A.unsafeFreeze marr
8788 return (Buf arr2 0 newlen newcap)
8889
90+ mconcat [] = mempty
91+ mconcat xs = foldl1' mappend xs
92+
8993length :: Buffer -> Int
9094length (Buf _ _ len _) = len
9195{-# INLINE length #-}