@@ -105,14 +105,12 @@ module Data.Text.Fusion
105import Prelude (Bool(..), Char, Either(..), Eq(..), Maybe(..), Monad(..),
105import Prelude (Bool(..), Char, Either(..), Eq(..), Maybe(..), Monad(..),
106 Num(..), Ord(..), String, ($), (++), (.), (&&),
106 Num(..), Ord(..), String, ($), (++), (.), (&&),
107 fromIntegral, otherwise)
107 fromIntegral, otherwise)
108−import Control.Monad (liftM2)
109−import Control.Monad.ST (runST)
110import qualified Data.List as L
108import qualified Data.List as L
111import GHC.Exts (Int(..), (+#))
109import GHC.Exts (Int(..), (+#))
112import Data.Bits ((.&.), shiftR)
110import Data.Bits ((.&.), shiftR)
113import Data.Char (ord)
111import Data.Char (ord)
114import Data.Text.Internal (Text(..))
112import Data.Text.Internal (Text(..))
115−import Data.Text.UnsafeChar (unsafeChr, unsafeWrite, unsafeWriteRev)
113+import Data.Text.UnsafeChar (unsafeChr, unsafeWrite)
116import qualified Data.Text.Array as A
114import qualified Data.Text.Array as A
117import Data.Text.Fusion.Internal
115import Data.Text.Fusion.Internal
118import qualified Data.Text.Internal as I
116import qualified Data.Text.Internal as I
@@ -154,18 +152,18 @@ reverseStream (Text arr off len) = Stream next (off+len-1) len
154-- | /O(n)/ Convert a 'Stream Char' into a 'Text'.
152-- | /O(n)/ Convert a 'Stream Char' into a 'Text'.
155unstream :: Stream Char -> Text
153unstream :: Stream Char -> Text
156unstream (Stream next0 s0 len)
154unstream (Stream next0 s0 len)
157− | len == 0 = I.empty
155+ | len == 0 = I.empty
158 | otherwise = I.textP (P.fst a) 0 (P.snd a)
156 | otherwise = I.textP (P.fst a) 0 (P.snd a)
160− a = runST (A.unsafeNew len >>= (\arr -> loop arr len s0 0))
158+ a = A.run2 (A.unsafeNew len >>= (\arr -> loop arr len s0 0))
161 loop arr !top !s !i
159 loop arr !top !s !i
162 | i + 1 >= top = case next0 s of
160 | i + 1 >= top = case next0 s of
163− Done -> liftM2 (,) (A.unsafeFreeze arr) (return i)
161+ Done -> return (arr, i)
165 arr' <- A.unsafeNew (top*2)
163 arr' <- A.unsafeNew (top*2)
166 A.copy arr arr' >> loop arr' (top*2) s i
164 A.copy arr arr' >> loop arr' (top*2) s i
167 | otherwise = case next0 s of
165 | otherwise = case next0 s of
168− Done -> liftM2 (,) (A.unsafeFreeze arr) (return i)
166+ Done -> return (arr, i)
169 Skip s' -> loop arr top s' i
167 Skip s' -> loop arr top s' i
170 Yield x s' -> unsafeWrite arr i x >>= loop arr top s'
168 Yield x s' -> unsafeWrite arr i x >>= loop arr top s'
171{-# INLINE [0] unstream #-}
169{-# INLINE [0] unstream #-}
@@ -377,14 +375,14 @@ reverse (Stream next s len0)
377 m = n - 0x10000
375 m = n - 0x10000
378 lo = fromIntegral $ (m `shiftR` 10) + 0xD800
376 lo = fromIntegral $ (m `shiftR` 10) + 0xD800
379 hi = fromIntegral $ (m .&. 0x3FF) + 0xDC00
377 hi = fromIntegral $ (m .&. 0x3FF) + 0xDC00
380− write s i len marr
378+ write t j l mar
381 | n < 0x10000 = do
379 | n < 0x10000 = do
382− A.unsafeWrite marr i (fromIntegral n)
380+ A.unsafeWrite mar j (fromIntegral n)
383− loop s (i-1) len marr
381+ loop t (j-1) l mar
384 | otherwise = do
382 | otherwise = do
385− A.unsafeWrite marr (i-1) lo
383+ A.unsafeWrite mar (j-1) lo
386− A.unsafeWrite marr i hi
384+ A.unsafeWrite mar j hi
387− loop s (i-2) len marr
385+ loop t (j-2) l mar
388{-# INLINE [0] reverse #-}
386{-# INLINE [0] reverse #-}
390-- ----------------------------------------------------------------------------
388-- ----------------------------------------------------------------------------