Commits

Bryan O'Sullivan committed 97566a7

Use unsafeIndex instead of index on ByteStrings

Comments (0)

Files changed (1)

Data/Text/Fusion.hs

 import Data.Array.Base
 import Data.Bits
 import qualified Data.ByteString as B
+import qualified Data.ByteString.Unsafe as B
 import Data.ByteString.Internal(ByteString(..),mallocByteString,memcpy)
 import qualified Data.List as L
 import Data.Word(Word8, Word16, Word32)
           | otherwise = Yield (unsafeChr8 x1) (i+1)
           where
             l  = B.length bs
-            x1 = B.index bs i
+            x1 = B.unsafeIndex bs i
 stream_bs Utf8 bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
             x2 = index (i + 1)
             x3 = index (i + 2)
             x4 = index (i + 3)
-            index = B.index bs
+            index = B.unsafeIndex bs
 stream_bs Utf16LE bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
             x2    :: Word16
             x2    = (shiftL (index (i + 3)) 8) + (index (i + 2))
             l     = B.length bs
-            index = fromIntegral . B.index bs :: Int -> Word16
+            index = fromIntegral . B.unsafeIndex bs :: Int -> Word16
 stream_bs Utf16BE bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
             x2    :: Word16
             x2    = (shiftL (index (i + 2)) 8) + (index (i + 3))
             l     = B.length bs
-            index = fromIntegral . B.index bs
+            index = fromIntegral . B.unsafeIndex bs
 stream_bs Utf32BE bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
             x2    = index (i+1)
             x3    = index (i+2)
             x4    = index (i+3)
-            index = fromIntegral . B.index bs :: Int -> Word32
+            index = fromIntegral . B.unsafeIndex bs :: Int -> Word32
 stream_bs Utf32LE bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
             x2    = index $ i+1
             x3    = index $ i+2
             x4    = index $ i+3
-            index = fromIntegral . B.index bs :: Int -> Word32
+            index = fromIntegral . B.unsafeIndex bs :: Int -> Word32
 {-# INLINE [0] stream_bs #-}
 
 -- | /O(n)/ Convert a Stream Char into a Stream Word8 using the specified encoding standard.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.