@@ -105,14 +105,12 @@ module Data.Text.Fusion
105105import Prelude (Bool(..), Char, Either(..), Eq(..), Maybe(..), Monad(..),
106106 Num(..), Ord(..), String, ($), (++), (.), (&&),
107107 fromIntegral, otherwise)
108−import Control.Monad (liftM2)
109−import Control.Monad.ST (runST)
110108import qualified Data.List as L
111109import GHC.Exts (Int(..), (+#))
112110import Data.Bits ((.&.), shiftR)
113111import Data.Char (ord)
114112import Data.Text.Internal (Text(..))
115−import Data.Text.UnsafeChar (unsafeChr, unsafeWrite, unsafeWriteRev)
113+import Data.Text.UnsafeChar (unsafeChr, unsafeWrite)
116114import qualified Data.Text.Array as A
117115import Data.Text.Fusion.Internal
118116import qualified Data.Text.Internal as I
@@ -154,18 +152,18 @@ reverseStream (Text arr off len) = Stream next (off+len-1) len
154152-- | /O(n)/ Convert a 'Stream Char' into a 'Text'.
155153unstream :: Stream Char -> Text
156154unstream (Stream next0 s0 len)
157− | len == 0 = I.empty
155+ | len == 0 = I.empty
158156 | otherwise = I.textP (P.fst a) 0 (P.snd a)
159157 where
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))
161159 loop arr !top !s !i
162160 | i + 1 >= top = case next0 s of
163− Done -> liftM2 (,) (A.unsafeFreeze arr) (return i)
161+ Done -> return (arr, i)
164162 _ -> do
165163 arr' <- A.unsafeNew (top*2)
166164 A.copy arr arr' >> loop arr' (top*2) s i
167165 | otherwise = case next0 s of
168− Done -> liftM2 (,) (A.unsafeFreeze arr) (return i)
166+ Done -> return (arr, i)
169167 Skip s' -> loop arr top s' i
170168 Yield x s' -> unsafeWrite arr i x >>= loop arr top s'
171169{-# INLINE [0] unstream #-}
@@ -377,14 +375,14 @@ reverse (Stream next s len0)
377375 m = n - 0x10000
378376 lo = fromIntegral $ (m `shiftR` 10) + 0xD800
379377 hi = fromIntegral $ (m .&. 0x3FF) + 0xDC00
380− write s i len marr
378+ write t j l mar
381379 | n < 0x10000 = do
382− A.unsafeWrite marr i (fromIntegral n)
383− loop s (i-1) len marr
380+ A.unsafeWrite mar j (fromIntegral n)
381+ loop t (j-1) l mar
384382 | otherwise = do
385− A.unsafeWrite marr (i-1) lo
386− A.unsafeWrite marr i hi
387− loop s (i-2) len marr
383+ A.unsafeWrite mar (j-1) lo
384+ A.unsafeWrite mar j hi
385+ loop t (j-2) l mar
388386{-# INLINE [0] reverse #-}
389387
390388-- ----------------------------------------------------------------------------