@@ -123,17 +123,18 @@ eq (Stream next1 s1 _) (Stream next2 s2 _) = compare (next1 s1) (next2 s2)
123123
124124-- | /O(n) Convert a ByteString into a Stream Char, using the specified encoding standard.
125125stream_bs :: Encoding -> ByteString -> Stream Char
126−stream_bs ASCII bs = Stream next 0 (B.length bs)
126+stream_bs ASCII bs = Stream next 0 l
127127 where
128+ l = B.length bs
128129 {-# INLINE next #-}
129130 next i
130131 | i >= l = Done
131132 | otherwise = Yield (unsafeChr8 x1) (i+1)
132133 where
133− l = B.length bs
134134 x1 = B.unsafeIndex bs i
135−stream_bs Utf8 bs = Stream next 0 (B.length bs)
135+stream_bs Utf8 bs = Stream next 0 l
136136 where
137+ l = B.length bs
137138 {-# INLINE next #-}
138139 next i
139140 | i >= l = Done
@@ -143,14 +144,14 @@ stream_bs Utf8 bs = Stream next 0 (B.length bs)
143144 | i+3 < l && U8.validate4 x1 x2 x3 x4 = Yield (U8.chr4 x1 x2 x3 x4) (i+4)
144145 | otherwise = error "bsStream: bad UTF-8 stream"
145146 where
146− l = B.length bs
147147 x1 = index i
148148 x2 = index (i + 1)
149149 x3 = index (i + 2)
150150 x4 = index (i + 3)
151151 index = B.unsafeIndex bs
152−stream_bs Utf16LE bs = Stream next 0 (B.length bs)
152+stream_bs Utf16LE bs = Stream next 0 l
153153 where
154+ l = B.length bs
154155 {-# INLINE next #-}
155156 next i
156157 | i >= l = Done
@@ -162,10 +163,10 @@ stream_bs Utf16LE bs = Stream next 0 (B.length bs)
162163 x1 = (shiftL (index (i + 1)) 8) + (index i)
163164 x2 :: Word16
164165 x2 = (shiftL (index (i + 3)) 8) + (index (i + 2))
165− l = B.length bs
166166 index = fromIntegral . B.unsafeIndex bs :: Int -> Word16
167−stream_bs Utf16BE bs = Stream next 0 (B.length bs)
167+stream_bs Utf16BE bs = Stream next 0 l
168168 where
169+ l = B.length bs
169170 {-# INLINE next #-}
170171 next i
171172 | i >= l = Done
@@ -177,32 +178,31 @@ stream_bs Utf16BE bs = Stream next 0 (B.length bs)
177178 x1 = (shiftL (index i) 8) + (index (i + 1))
178179 x2 :: Word16
179180 x2 = (shiftL (index (i + 2)) 8) + (index (i + 3))
180− l = B.length bs
181181 index = fromIntegral . B.unsafeIndex bs
182−stream_bs Utf32BE bs = Stream next 0 (B.length bs)
182+stream_bs Utf32BE bs = Stream next 0 l
183183 where
184+ l = B.length bs
184185 {-# INLINE next #-}
185186 next i
186187 | i >= l = Done
187188 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
188189 | otherwise = error "bsStream: bad UTF-32BE stream"
189190 where
190− l = B.length bs
191191 x = shiftL x1 24 + shiftL x2 16 + shiftL x3 8 + x4
192192 x1 = index i
193193 x2 = index (i+1)
194194 x3 = index (i+2)
195195 x4 = index (i+3)
196196 index = fromIntegral . B.unsafeIndex bs :: Int -> Word32
197−stream_bs Utf32LE bs = Stream next 0 (B.length bs)
197+stream_bs Utf32LE bs = Stream next 0 l
198198 where
199+ l = B.length bs
199200 {-# INLINE next #-}
200201 next i
201202 | i >= l = Done
202203 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
203204 | otherwise = error "bsStream: bad UTF-32LE stream"
204205 where
205− l = B.length bs
206206 x = shiftL x4 24 + shiftL x3 16 + shiftL x2 8 + x1
207207 x1 = index i
208208 x2 = index $ i+1