on master help sign in
Get rid of some compiler warnings.
3cb61bfBryan O'Sullivan
Data/Text/Encoding/Fusion.hs+5−6
@@ -161,23 +161,22 @@ streamUtf32LE bs = Stream next 0 l
161-- | /O(n)/ Convert a 'Stream' 'Word8' to a 'ByteString'.
161-- | /O(n)/ Convert a 'Stream' 'Word8' to a 'ByteString'.
162unstream :: Stream Word8 -> ByteString
162unstream :: Stream Word8 -> ByteString
163unstream (Stream next s0 len) = unsafePerformIO $ do
163unstream (Stream next s0 len) = unsafePerformIO $ do
164− fp0 <- mallocByteString len
164+ mallocByteString len >>= loop len 0 s0
165− loop fp0 len 0 s0
166 where
165 where
167− loop !fp !n !off !s = case next s of
166+ loop !n !off !s fp = case next s of
168 Done -> trimUp fp n off
167 Done -> trimUp fp n off
169− Skip s' -> loop fp n off s'
168+ Skip s' -> loop n off s' fp
170 Yield x s'
169 Yield x s'
171 | off == n -> realloc fp n off s' x
170 | off == n -> realloc fp n off s' x
172 | otherwise -> do
171 | otherwise -> do
173 withForeignPtr fp $ \p -> pokeByteOff p off x
172 withForeignPtr fp $ \p -> pokeByteOff p off x
174− loop fp n (off+1) s'
173+ loop n (off+1) s' fp
175 {-# NOINLINE realloc #-}
174 {-# NOINLINE realloc #-}
176 realloc fp n off s x = do
175 realloc fp n off s x = do
177 let n' = n+n
176 let n' = n+n
178 fp' <- copy0 fp n n'
177 fp' <- copy0 fp n n'
179 withForeignPtr fp' $ \p -> pokeByteOff p off x
178 withForeignPtr fp' $ \p -> pokeByteOff p off x
180− loop fp' n' (off+1) s
179+ loop n' (off+1) s fp'
181 {-# NOINLINE trimUp #-}
180 {-# NOINLINE trimUp #-}
182 trimUp fp _ off = return $! PS fp 0 off
181 trimUp fp _ off = return $! PS fp 0 off
183 copy0 :: ForeignPtr Word8 -> Int -> Int -> IO (ForeignPtr Word8)
182 copy0 :: ForeignPtr Word8 -> Int -> Int -> IO (ForeignPtr Word8)
Data/Text/Encoding/Fusion/Common.hs+1−1
@@ -27,7 +27,7 @@ module Data.Text.Encoding.Fusion.Common
27 , restreamUtf32BE
27 , restreamUtf32BE
28 ) where
28 ) where
29
29
30−import Data.Bits (shiftL, shiftR, (.&.))
30+import Data.Bits (shiftR, (.&.))
31import Data.Char (ord)
31import Data.Char (ord)
32import Data.Text.Fusion (Step(..), Stream(..))
32import Data.Text.Fusion (Step(..), Stream(..))
33import Data.Text.Fusion.Internal (M(..), S(..))
33import Data.Text.Fusion.Internal (M(..), S(..))
Data/Text/Lazy/Encoding/Fusion.hs+14−15
@@ -35,7 +35,7 @@ import qualified Data.ByteString.Unsafe as B
35import Data.Text.Encoding.Fusion.Common
35import Data.Text.Encoding.Fusion.Common
36import Data.Text.Fusion (Step(..), Stream(..))
36import Data.Text.Fusion (Step(..), Stream(..))
37import Data.Text.Fusion.Internal (M(..), PairS(..), S(..))
37import Data.Text.Fusion.Internal (M(..), PairS(..), S(..))
38−import Data.Text.UnsafeChar (unsafeChr, unsafeChr8, unsafeChr32)
38+import Data.Text.UnsafeChar (unsafeChr8)
39import Data.Word (Word8)
39import Data.Word (Word8)
40import qualified Data.Text.Encoding.Utf8 as U8
40import qualified Data.Text.Encoding.Utf8 as U8
41import System.IO.Unsafe (unsafePerformIO)
41import System.IO.Unsafe (unsafePerformIO)
@@ -67,49 +67,48 @@ streamUtf8 bs0 = Stream next (bs0 :!: S N N N N :!: 0) unknownLength
67 _ -> consume st
67 _ -> consume st
68 where es = bs :!: S N N N N :!: i
68 where es = bs :!: S N N N N :!: i
69 {-# INLINE consume #-}
69 {-# INLINE consume #-}
70− consume (c@(Chunk bs rest) :!: s :!: i)
70+ consume (bs@(Chunk ps rest) :!: s :!: i)
71 | i >= len = consume (rest :!: s :!: 0)
71 | i >= len = consume (rest :!: s :!: 0)
72− | otherwise = next (c :!: s' :!: i+1)
72+ | otherwise = next (bs :!: s' :!: i+1)
73 where s' = case s of
73 where s' = case s of
74 S N _ _ _ -> S x N N N
74 S N _ _ _ -> S x N N N
75 S a N _ _ -> S a x N N
75 S a N _ _ -> S a x N N
76 S a b N _ -> S a b x N
76 S a b N _ -> S a b x N
77 S a b c N -> S a b c x
77 S a b c N -> S a b c x
78 _ -> encodingError "streamUtf8" "UTF-8"
78 _ -> encodingError "streamUtf8" "UTF-8"
79− x = J (B.unsafeIndex bs i)
79+ x = J (B.unsafeIndex ps i)
80− len = B.length bs
80+ len = B.length ps
81 consume (Empty :!: S N _ _ _ :!: _) = Done
81 consume (Empty :!: S N _ _ _ :!: _) = Done
82 consume _ = encodingError "streamUtf8" "UTF-8"
82 consume _ = encodingError "streamUtf8" "UTF-8"
83{-# INLINE [0] streamUtf8 #-}
83{-# INLINE [0] streamUtf8 #-}
84
84
85-- | /O(n)/ Convert a 'Stream' 'Word8' to a lazy 'ByteString'.
85-- | /O(n)/ Convert a 'Stream' 'Word8' to a lazy 'ByteString'.
86unstreamChunks :: Int -> Stream Word8 -> ByteString
86unstreamChunks :: Int -> Stream Word8 -> ByteString
87−unstreamChunks chunkSize (Stream next s0 len) = chunk s0 len
87+unstreamChunks chunkSize (Stream next s0 len0) = chunk s0 len0
88− where chunk s0 len = unsafePerformIO $ do
88+ where chunk s1 len1 = unsafePerformIO $ do
89− let safeLen = min (max len unknownLength) chunkSize
89+ let len = min (max len1 unknownLength) chunkSize
90− fp0 <- mallocByteString safeLen
90+ mallocByteString len >>= loop len 0 s1
91− loop fp0 safeLen 0 s0
92 where
91 where
93− loop !fp !n !off !s = case next s of
92+ loop !n !off !s fp = case next s of
94 Done | off == 0 -> return Empty
93 Done | off == 0 -> return Empty
95 | otherwise -> do
94 | otherwise -> do
96 bs <- trimUp fp off
95 bs <- trimUp fp off
97 return $! Chunk bs Empty
96 return $! Chunk bs Empty
98− Skip s' -> loop fp n off s'
97+ Skip s' -> loop n off s' fp
99 Yield x s'
98 Yield x s'
100 | off == chunkSize -> do
99 | off == chunkSize -> do
101 bs <- trimUp fp off
100 bs <- trimUp fp off
102− return (Chunk bs (chunk s (len - B.length bs)))
101+ return (Chunk bs (chunk s (n - B.length bs)))
103 | off == n -> realloc fp n off s' x
102 | off == n -> realloc fp n off s' x
104 | otherwise -> do
103 | otherwise -> do
105 withForeignPtr fp $ \p -> pokeByteOff p off x
104 withForeignPtr fp $ \p -> pokeByteOff p off x
106− loop fp n (off+1) s'
105+ loop n (off+1) s' fp
107 {-# NOINLINE realloc #-}
106 {-# NOINLINE realloc #-}
108 realloc fp n off s x = do
107 realloc fp n off s x = do
109 let n' = min (n+n) chunkSize
108 let n' = min (n+n) chunkSize
110 fp' <- copy0 fp n n'
109 fp' <- copy0 fp n n'
111 withForeignPtr fp' $ \p -> pokeByteOff p off x
110 withForeignPtr fp' $ \p -> pokeByteOff p off x
112− loop fp' n' (off+1) s
111+ loop n' (off+1) s fp'
113 {-# NOINLINE trimUp #-}
112 {-# NOINLINE trimUp #-}
114 trimUp fp off = return $! B.PS fp 0 off
113 trimUp fp off = return $! B.PS fp 0 off
115 copy0 :: ForeignPtr Word8 -> Int -> Int -> IO (ForeignPtr Word8)
114 copy0 :: ForeignPtr Word8 -> Int -> Int -> IO (ForeignPtr Word8)