Skip to content

Commit

Permalink
Manually define sconcat to use the efficient concat function
Browse files Browse the repository at this point in the history
  • Loading branch information
gwils committed May 11, 2020
1 parent fc09348 commit 757cf1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Fix GHC Travis CI 7.0 builds
* Fix benchmark builds
* Add GHC 8.10 to the CI matrix
* Improve the performance of `sconcat` for lazy and strict bytestrings

0.10.10.0 July 2019 <duncan+haskell@dcoutts.me.uk> July 2019

Expand Down
10 changes: 8 additions & 2 deletions Data/ByteString/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,14 @@ import Foreign.C.Types (CInt, CSize, CULong)

import Foreign.C.String (CString)

#if !(MIN_VERSION_base(4,11,0)) && MIN_VERSION_base(4,9,0)
import Data.Semigroup (Semigroup((<>)))
#if MIN_VERSION_base(4,13,0)
import Data.Semigroup (Semigroup (sconcat))
import Data.List.NonEmpty (NonEmpty ((:|)))
#elif MIN_VERSION_base(4,9,0)
import Data.Semigroup (Semigroup ((<>), sconcat))
import Data.List.NonEmpty (NonEmpty ((:|)))
#endif

#if !(MIN_VERSION_base(4,8,0))
import Data.Monoid (Monoid(..))
#endif
Expand Down Expand Up @@ -156,6 +161,7 @@ instance Ord ByteString where
#if MIN_VERSION_base(4,9,0)
instance Semigroup ByteString where
(<>) = append
sconcat (b:|bs) = concat (b:bs)
#endif

instance Monoid ByteString where
Expand Down
9 changes: 7 additions & 2 deletions Data/ByteString/Lazy/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ import qualified Data.ByteString as S (length, take, drop)
import Data.Word (Word8)
import Foreign.Storable (Storable(sizeOf))

#if !(MIN_VERSION_base(4,11,0)) && MIN_VERSION_base(4,9,0)
import Data.Semigroup (Semigroup((<>)))
#if MIN_VERSION_base(4,13,0)
import Data.Semigroup (Semigroup (sconcat))
import Data.List.NonEmpty (NonEmpty ((:|)))
#elif MIN_VERSION_base(4,9,0)
import Data.Semigroup (Semigroup ((<>), sconcat))
import Data.List.NonEmpty (NonEmpty ((:|)))
#endif
#if !(MIN_VERSION_base(4,8,0))
import Data.Monoid (Monoid(..))
Expand Down Expand Up @@ -84,6 +88,7 @@ instance Ord ByteString where
#if MIN_VERSION_base(4,9,0)
instance Semigroup ByteString where
(<>) = append
sconcat (b:|bs) = concat (b:bs)
#endif

instance Monoid ByteString where
Expand Down

0 comments on commit 757cf1e

Please sign in to comment.