@@ -108,9 +108,10 @@ import qualified Prelude as P
108108import Data.Int (Int64)
109109import Data.Text.Fusion.Internal
110110import Data.Text.Fusion.CaseMapping (foldMapping, lowerMapping, upperMapping)
111+import Data.Text.Fusion.Size
111112
112113singleton :: Char -> Stream Char
113−singleton c = Stream next False 1 -- HINT maybe too low
114+singleton c = Stream next False 1
114115 where next False = Yield c True
115116 next True = Done
116117{-# INLINE singleton #-}
@@ -118,10 +119,9 @@ singleton c = Stream next False 1 -- HINT maybe too low
118119streamList :: [a] -> Stream a
119120{-# INLINE [0] streamList #-}
120121streamList [] = empty
121−streamList s = Stream next s unknownLength
122+streamList s = Stream next s unknownSize
122123 where next [] = Done
123124 next (x:xs) = Yield x xs
124− unknownLength = 8 -- random HINT
125125
126126unstreamList :: Stream a -> [a]
127127{-# INLINE [0] unstreamList #-}
@@ -138,7 +138,7 @@ unstreamList (Stream next s0 _len) = unfold s0
138138
139139-- | /O(n)/ Adds a character to the front of a Stream Char.
140140cons :: Char -> Stream Char -> Stream Char
141−cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2) -- HINT maybe too high
141+cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+1)
142142 where
143143 {-# INLINE next #-}
144144 next (S2 :!: s) = Yield w (S1 :!: s)
@@ -150,7 +150,7 @@ cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2) -- HINT maybe too
150150
151151-- | /O(n)/ Adds a character to the end of a stream.
152152snoc :: Stream Char -> Char -> Stream Char
153−snoc (Stream next0 xs0 len) w = Stream next (J xs0) (len+2) -- HINT maybe too high
153+snoc (Stream next0 xs0 len) w = Stream next (J xs0) (len+1)
154154 where
155155 {-# INLINE next #-}
156156 next (J xs) = case next0 xs of
@@ -193,7 +193,7 @@ uncons :: Stream Char -> Maybe (Char, Stream Char)
193193uncons (Stream next s0 len) = loop_uncons s0
194194 where
195195 loop_uncons !s = case next s of
196− Yield x s1 -> Just (x, Stream next s1 (len-1)) -- HINT maybe too high
196+ Yield x s1 -> Just (x, Stream next s1 (len-1))
197197 Skip s' -> loop_uncons s'
198198 Done -> Nothing
199199{-# INLINE [0] uncons #-}
@@ -216,7 +216,7 @@ last (Stream next s0 _len) = loop0_last s0
216216-- | /O(1)/ Returns all characters after the head of a Stream Char, which must
217217-- be non-empty.
218218tail :: Stream Char -> Stream Char
219−tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1) -- HINT maybe too high
219+tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1)
220220 where
221221 {-# INLINE next #-}
222222 next (False :!: s) = case next0 s of
@@ -233,7 +233,7 @@ tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1) -- HINT maybe to
233233-- | /O(1)/ Returns all but the last character of a Stream Char, which
234234-- must be non-empty.
235235init :: Stream Char -> Stream Char
236−init (Stream next0 s0 len) = Stream next (N :!: s0) (len-1) -- HINT maybe too high
236+init (Stream next0 s0 len) = Stream next (N :!: s0) (len-1)
237237 where
238238 {-# INLINE next #-}
239239 next (N :!: s) = case next0 s of
@@ -269,10 +269,10 @@ lengthI (Stream next s0 _len) = loop_length 0 s0
269269-- ----------------------------------------------------------------------------
270270-- * Stream transformations
271271
272−-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
273−-- @xs@.
272+-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@
273+-- to each element of @xs@.
274274map :: (Char -> Char) -> Stream Char -> Stream Char
275−map f (Stream next0 s0 len) = Stream next s0 len -- HINT depends on f
275+map f (Stream next0 s0 len) = Stream next s0 len
276276 where
277277 {-# INLINE next #-}
278278 next !s = case next0 s of
@@ -289,7 +289,7 @@ map f (Stream next0 s0 len) = Stream next s0 len -- HINT depends on f
289289-- | /O(n)/ Take a character and place it between each of the
290290-- characters of a 'Stream Char'.
291291intersperse :: Char -> Stream Char -> Stream Char
292−intersperse c (Stream next0 s0 len) = Stream next (s0 :!: N :!: S1) len -- HINT maybe too low
292+intersperse c (Stream next0 s0 len) = Stream next (s0 :!: N :!: S1) len
293293 where
294294 {-# INLINE next #-}
295295 next (s :!: N :!: S1) = case next0 s of
@@ -364,11 +364,9 @@ toLower = caseConvert lowerMapping
364364{-# INLINE [0] toLower #-}
365365
366366justifyLeftI :: Integral a => a -> Char -> Stream Char -> Stream Char
367−justifyLeftI k c (Stream next0 s0 len) = Stream next (s0 :!: S1 :!: 0) newLen
367+justifyLeftI k c (Stream next0 s0 len) =
368+ Stream next (s0 :!: S1 :!: 0) (larger (fromIntegral k) len)
368369 where
369− j = fromIntegral k
370− newLen | j > len = j
371− | otherwise = len
372370 next (s :!: S1 :!: n) =
373371 case next0 s of
374372 Done -> next (s :!: S2 :!: n)
@@ -590,7 +588,7 @@ replicateCharI n c
590588
591589replicateI :: Int64 -> Stream Char -> Stream Char
592590replicateI n (Stream next0 s0 len) =
593− Stream next (0 :!: s0) (max 0 (fromIntegral n * len))
591+ Stream next (0 :!: s0) (fromIntegral (max 0 n) * len)
594592 where
595593 next (k :!: s)
596594 | k >= n = Done
@@ -638,7 +636,7 @@ unfoldrNI n f s0 | n < 0 = empty
638636-- length of the stream.
639637take :: Integral a => a -> Stream Char -> Stream Char
640638take n0 (Stream next0 s0 len) =
641− Stream next (n0 :!: s0) (max 0 (len - fromIntegral n0)) -- HINT maybe too high
639+ Stream next (n0 :!: s0) (smaller len (fromIntegral (max 0 n0)))
642640 where
643641 {-# INLINE next #-}
644642 next (n :!: s) | n <= 0 = Done
@@ -653,11 +651,11 @@ take n0 (Stream next0 s0 len) =
653651-- length of the stream.
654652drop :: Integral a => a -> Stream Char -> Stream Char
655653drop n0 (Stream next0 s0 len) =
656− Stream next (J (max 0 n0) :!: s0) (len - fromIntegral n0) -- HINT maybe too high
654+ Stream next (J n0 :!: s0) (len - fromIntegral (max 0 n0))
657655 where
658656 {-# INLINE next #-}
659657 next (J n :!: s)
660− | n == 0 = Skip (N :!: s)
658+ | n <= 0 = Skip (N :!: s)
661659 | otherwise = case next0 s of
662660 Done -> Done
663661 Skip s' -> Skip (J n :!: s')
@@ -806,7 +804,8 @@ findIndicesI p (Stream next s0 _len) = loop_findIndex 0 s0
806804-- | zipWith generalises 'zip' by zipping with the function given as
807805-- the first argument, instead of a tupling function.
808806zipWith :: (a -> a -> b) -> Stream a -> Stream a -> Stream b
809−zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) = Stream next (sa0 :!: sb0 :!: N) (min len1 len2)
807+zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) =
808+ Stream next (sa0 :!: sb0 :!: N) (smaller len1 len2)
810809 where
811810 {-# INLINE next #-}
812811 next (sa :!: sb :!: N) = case next0 sa of