@@ -1,4 +1,4 @@
1−{-# LANGUAGE BangPatterns, CPP, ForeignFunctionInterface, MagicHash,
1+{-# LANGUAGE BangPatterns, CPP, ForeignFunctionInterface, GeneralizedNewtypeDeriving, MagicHash,
22 UnliftedFFITypes #-}
33#if __GLASGOW_HASKELL__ >= 702
44{-# LANGUAGE Trustworthy #-}
@@ -75,7 +75,7 @@ import Foreign.C.Types (CSize)
7575import Foreign.ForeignPtr (withForeignPtr)
7676import Foreign.Marshal.Utils (with)
7777import Foreign.Ptr (Ptr, minusPtr, plusPtr)
78−import Foreign.Storable (peek, poke)
78+import Foreign.Storable (Storable, peek, poke)
7979import GHC.Base (MutableByteArray#)
8080import qualified Data.Text.Array as A
8181import qualified Data.Text.Encoding.Fusion as E
@@ -148,16 +148,16 @@ decodeUtf8With onErr (PS fp off len) = runText $ \done -> do
148148
149149data Decoder = Some !Text (ByteString -> Decoder)
150150
151−-- | (codepoint, state)
152−type DecoderState = (Word32, Word32)
151+newtype CodePoint = CodePoint Word32 deriving (Num, Storable)
152+newtype DecoderState = DecoderState Word32 deriving (Eq, Num, Storable)
153153
154154decodeUtf8With' :: OnDecodeError -> ByteString -> Decoder
155−decodeUtf8With' onErr = decodeChunk (0,0)
155+decodeUtf8With' onErr = decodeChunk 0 0
156156 where
157157 -- We create a slightly larger than necessary buffer to accomodate a
158158 -- potential surrogate pair started in the last buffer
159− decodeChunk :: DecoderState -> ByteString -> Decoder
160− decodeChunk (codepoint0,state0) (PS fp off len) =
159+ decodeChunk :: CodePoint -> DecoderState -> ByteString -> Decoder
160+ decodeChunk codepoint0 state0 (PS fp off len) =
161161 runST $ (unsafeIOToST . decodeChunkToBuffer) =<< A.new (len+1)
162162 where
163163 decodeChunkToBuffer :: A.MArray s -> IO Decoder
@@ -191,7 +191,7 @@ decodeUtf8With' onErr = decodeChunk (0,0)
191191 chunkText <- unsafeSTToIO $ do
192192 arr <- A.unsafeFreeze dest
193193 return $! textP arr 0 (fromIntegral n)
194− return $ Some chunkText $ decodeChunk (codepoint, state)
194+ return $ Some chunkText $ decodeChunk codepoint state
195195 in loop (ptr `plusPtr` off)
196196 desc = "Data.Text.Encoding.decodeUtf8With': Invalid UTF-8 stream"
197197{- INLINE[0] decodeUtf8With' #-}
@@ -356,7 +356,7 @@ foreign import ccall unsafe "_hs_text_decode_utf8" c_decode_utf8
356356foreign import ccall unsafe "_hs_text_decode_utf8_state" c_decode_utf8_with_state
357357 :: MutableByteArray# s -> Ptr CSize
358358 -> Ptr Word8 -> Ptr Word8
359− -> Ptr Word32 -> Ptr Word32 -> IO (Ptr Word8)
359+ -> Ptr CodePoint -> Ptr DecoderState -> IO (Ptr Word8)
360360
361361foreign import ccall unsafe "_hs_text_decode_latin1" c_decode_latin1
362362 :: MutableByteArray# s -> Ptr Word8 -> Ptr Word8 -> IO ()