on master help sign in
Use unsafeIndex instead of index on ByteStrings
5e688aaBryan O'Sullivan
Data/Text/Fusion.hs+7−6
@@ -13,6 +13,7 @@ import Control.Monad.ST(runST,ST)
13import Data.Array.Base
13import Data.Array.Base
14import Data.Bits
14import Data.Bits
15import qualified Data.ByteString as B
15import qualified Data.ByteString as B
16+import qualified Data.ByteString.Unsafe as B
16import Data.ByteString.Internal(ByteString(..),mallocByteString,memcpy)
17import Data.ByteString.Internal(ByteString(..),mallocByteString,memcpy)
17import qualified Data.List as L
18import qualified Data.List as L
18import Data.Word(Word8, Word16, Word32)
19import Data.Word(Word8, Word16, Word32)
@@ -129,7 +130,7 @@ stream_bs ASCII bs = Stream next 0 (B.length bs)
129 | otherwise = Yield (unsafeChr8 x1) (i+1)
130 | otherwise = Yield (unsafeChr8 x1) (i+1)
130 where
131 where
131 l = B.length bs
132 l = B.length bs
132− x1 = B.index bs i
133+ x1 = B.unsafeIndex bs i
133stream_bs Utf8 bs = Stream next 0 (B.length bs)
134stream_bs Utf8 bs = Stream next 0 (B.length bs)
134 where
135 where
135 {-# INLINE next #-}
136 {-# INLINE next #-}
@@ -146,7 +147,7 @@ stream_bs Utf8 bs = Stream next 0 (B.length bs)
146 x2 = index (i + 1)
147 x2 = index (i + 1)
147 x3 = index (i + 2)
148 x3 = index (i + 2)
148 x4 = index (i + 3)
149 x4 = index (i + 3)
149− index = B.index bs
150+ index = B.unsafeIndex bs
150stream_bs Utf16LE bs = Stream next 0 (B.length bs)
151stream_bs Utf16LE bs = Stream next 0 (B.length bs)
151 where
152 where
152 {-# INLINE next #-}
153 {-# INLINE next #-}
@@ -161,7 +162,7 @@ stream_bs Utf16LE bs = Stream next 0 (B.length bs)
161 x2 :: Word16
162 x2 :: Word16
162 x2 = (shiftL (index (i + 3)) 8) + (index (i + 2))
163 x2 = (shiftL (index (i + 3)) 8) + (index (i + 2))
163 l = B.length bs
164 l = B.length bs
164− index = fromIntegral . B.index bs :: Int -> Word16
165+ index = fromIntegral . B.unsafeIndex bs :: Int -> Word16
165stream_bs Utf16BE bs = Stream next 0 (B.length bs)
166stream_bs Utf16BE bs = Stream next 0 (B.length bs)
166 where
167 where
167 {-# INLINE next #-}
168 {-# INLINE next #-}
@@ -176,7 +177,7 @@ stream_bs Utf16BE bs = Stream next 0 (B.length bs)
176 x2 :: Word16
177 x2 :: Word16
177 x2 = (shiftL (index (i + 2)) 8) + (index (i + 3))
178 x2 = (shiftL (index (i + 2)) 8) + (index (i + 3))
178 l = B.length bs
179 l = B.length bs
179− index = fromIntegral . B.index bs
180+ index = fromIntegral . B.unsafeIndex bs
180stream_bs Utf32BE bs = Stream next 0 (B.length bs)
181stream_bs Utf32BE bs = Stream next 0 (B.length bs)
181 where
182 where
182 {-# INLINE next #-}
183 {-# INLINE next #-}
@@ -191,7 +192,7 @@ stream_bs Utf32BE bs = Stream next 0 (B.length bs)
191 x2 = index (i+1)
192 x2 = index (i+1)
192 x3 = index (i+2)
193 x3 = index (i+2)
193 x4 = index (i+3)
194 x4 = index (i+3)
194− index = fromIntegral . B.index bs :: Int -> Word32
195+ index = fromIntegral . B.unsafeIndex bs :: Int -> Word32
195stream_bs Utf32LE bs = Stream next 0 (B.length bs)
196stream_bs Utf32LE bs = Stream next 0 (B.length bs)
196 where
197 where
197 {-# INLINE next #-}
198 {-# INLINE next #-}
@@ -206,7 +207,7 @@ stream_bs Utf32LE bs = Stream next 0 (B.length bs)
206 x2 = index $ i+1
207 x2 = index $ i+1
207 x3 = index $ i+2
208 x3 = index $ i+2
208 x4 = index $ i+3
209 x4 = index $ i+3
209− index = fromIntegral . B.index bs :: Int -> Word32
210+ index = fromIntegral . B.unsafeIndex bs :: Int -> Word32
210{-# INLINE [0] stream_bs #-}
211{-# INLINE [0] stream_bs #-}
211
212
212-- | /O(n)/ Convert a Stream Char into a Stream Word8 using the specified encoding standard.
213-- | /O(n)/ Convert a Stream Char into a Stream Word8 using the specified encoding standard.