@@ -48,7 +48,7 @@ module Data.Text.Fusion
50import Prelude (Bool(..), Char, Eq(..), Maybe(..), Monad(..), Int,
50import Prelude (Bool(..), Char, Eq(..), Maybe(..), Monad(..), Int,
51− Num(..), Ord(..), String, ($), (++), (&&),
51+ Num(..), Ord(..), ($), (&&),
52 fromIntegral, otherwise)
52 fromIntegral, otherwise)
53import Data.Bits ((.&.), shiftR)
53import Data.Bits ((.&.), shiftR)
54import Data.Char (ord)
54import Data.Char (ord)
@@ -181,17 +181,9 @@ unfoldrN n = S.unfoldrNI n
181-------------------------------------------------------------------------------
181-------------------------------------------------------------------------------
182-- ** Indexing streams
182-- ** Indexing streams
184−-- | /O(1)/ stream index (subscript) operator, starting from 0.
184+-- | /O(n)/ stream index (subscript) operator, starting from 0.
185index :: Stream Char -> Int -> Char
185index :: Stream Char -> Int -> Char
186−index (Stream next s0 _len) n0
186+index = S.indexI
187− | n0 < 0 = streamError "index" "Negative index"
188− | otherwise = loop_index n0 s0
190− loop_index !n !s = case next s of
191− Done -> streamError "index" "Index too large"
192− Skip s' -> loop_index n s'
193− Yield x s' | n == 0 -> x
194− | otherwise -> loop_index (n-1) s'
195{-# INLINE [0] index #-}
187{-# INLINE [0] index #-}
197-- | The 'findIndex' function takes a predicate and a stream and
189-- | The 'findIndex' function takes a predicate and a stream and
@@ -261,6 +253,3 @@ count a (Stream next s0 _len) = loop 0 s0
261 Yield x s' | a == x -> loop (i+1) s'
253 Yield x s' | a == x -> loop (i+1) s'
262 | otherwise -> loop i s'
254 | otherwise -> loop i s'
263{-# INLINE [0] count #-}
255{-# INLINE [0] count #-}
265−streamError :: String -> String -> a
266−streamError func msg = P.error $ "Data.Text.Fusion." ++ func ++ ": " ++ msg