@@ -98,7 +98,7 @@ module Data.Text.Fusion.Common
101−import Prelude (Bool(..), Char, Either(..), Eq(..), Int, Integral, Maybe(..),
101+import Prelude (Bool(..), Char, Eq(..), Int, Integral, Maybe(..),
102 Ord(..), String, (.), ($), (+), (-), (*), (++), (&&),
102 Ord(..), String, (.), ($), (+), (-), (*), (++), (&&),
103 fromIntegral, otherwise)
103 fromIntegral, otherwise)
104import qualified Data.List as L
104import qualified Data.List as L
@@ -157,20 +157,22 @@ snoc (Stream next0 xs0 len) w = Stream next (J xs0) (len+1)
157 next N = Done
157 next N = Done
158{-# INLINE [0] snoc #-}
158{-# INLINE [0] snoc #-}
160+data E l r = L {-# UNPACK #-} !l
161+ | R {-# UNPACK #-} !r
160-- | /O(n)/ Appends one Stream to the other.
163-- | /O(n)/ Appends one Stream to the other.
161append :: Stream Char -> Stream Char -> Stream Char
164append :: Stream Char -> Stream Char -> Stream Char
162append (Stream next0 s01 len1) (Stream next1 s02 len2) =
165append (Stream next0 s01 len1) (Stream next1 s02 len2) =
163− Stream next (Left s01) (len1 + len2)
166+ Stream next (L s01) (len1 + len2)
166− next (Left s1) = case next0 s1 of
168+ next (L s1) = case next0 s1 of
167− Done -> Skip (Right s02)
169+ Done -> Skip (R s02)
168− Skip s1' -> Skip (Left s1')
170+ Skip s1' -> Skip (L s1')
169− Yield x s1' -> Yield x (Left s1')
171+ Yield x s1' -> Yield x (L s1')
170− next (Right s2) = case next1 s2 of
172+ next (R s2) = case next1 s2 of
171 Done -> Done
173 Done -> Done
172− Skip s2' -> Skip (Right s2')
174+ Skip s2' -> Skip (R s2')
173− Yield x s2' -> Yield x (Right s2')
175+ Yield x s2' -> Yield x (R s2')
174{-# INLINE [0] append #-}
176{-# INLINE [0] append #-}
176-- | /O(1)/ Returns the first character of a Text, which must be non-empty.
178-- | /O(1)/ Returns the first character of a Text, which must be non-empty.
@@ -283,7 +285,6 @@ isSingleton (Stream next s0 _len) = loop 0 s0
283map :: (Char -> Char) -> Stream Char -> Stream Char
285map :: (Char -> Char) -> Stream Char -> Stream Char
284map f (Stream next0 s0 len) = Stream next s0 len
286map f (Stream next0 s0 len) = Stream next s0 len
287 next !s = case next0 s of
288 next !s = case next0 s of
288 Done -> Done
289 Done -> Done
289 Skip s' -> Skip s'
290 Skip s' -> Skip s'