@@ -111,7 +111,7 @@ import qualified Data.List as L
111import Data.Word (Word16)
111import Data.Word (Word16)
112import GHC.Exts (Int(..), (+#))
112import GHC.Exts (Int(..), (+#))
113import Data.Text.Internal (Text(..))
113import Data.Text.Internal (Text(..))
114−import Data.Text.UnsafeChar (unsafeChr)
114+import Data.Text.UnsafeChar (unsafeChr, unsafeWrite)
115import qualified Data.Text.Array as A
115import qualified Data.Text.Array as A
116import qualified Data.Text.Internal as I
116import qualified Data.Text.Internal as I
117import qualified Data.Text.Utf16 as U16
117import qualified Data.Text.Utf16 as U16
@@ -149,29 +149,17 @@ unstream :: Stream Char -> Text
149unstream (Stream _next0 _s0 0) = I.empty
149unstream (Stream _next0 _s0 0) = I.empty
150unstream (Stream next0 s0 len) = Text (fst a) 0 (snd a)
150unstream (Stream next0 s0 len) = Text (fst a) 0 (snd a)
152− a = runST (A.unsafeNew len >>= (\arr -> loop arr 0 len s0))
152+ a = runST (A.unsafeNew len >>= (\arr -> loop arr len s0 0))
153− loop arr !i !top !s
153+ loop arr !top !s !i
154 | i + 1 >= top = case next0 s of
154 | i + 1 >= top = case next0 s of
155 Done -> liftM2 (,) (A.unsafeFreeze arr) (return i)
155 Done -> liftM2 (,) (A.unsafeFreeze arr) (return i)
157 arr' <- A.unsafeNew (top*2)
157 arr' <- A.unsafeNew (top*2)
158− copy arr arr' >> loop arr' i (top*2) s
158+ copy arr arr' >> loop arr' (top*2) s i
159 | otherwise = case next0 s of
159 | otherwise = case next0 s of
160 Done -> liftM2 (,) (A.unsafeFreeze arr) (return i)
160 Done -> liftM2 (,) (A.unsafeFreeze arr) (return i)
161− Skip s' -> loop arr i top s'
161+ Skip s' -> loop arr top s' i
164− A.unsafeWrite arr i (fromIntegral n)
162+ Yield x s' -> unsafeWrite arr i x >>= loop arr top s'
165− loop arr (i+1) top s'
167− A.unsafeWrite arr i l
168− A.unsafeWrite arr (i + 1) r
169− loop arr (i+2) top s'
173− l = fromIntegral $ (m `shiftR` 10) + 0xD800
174− r = fromIntegral $ (m .&. 0x3FF) + 0xDC00
175{-# INLINE [0] unstream #-}
163{-# INLINE [0] unstream #-}
176{-# RULES "STREAM stream/unstream fusion" forall s. stream (unstream s) = s #-}
164{-# RULES "STREAM stream/unstream fusion" forall s. stream (unstream s) = s #-}