@@ -51,6 +51,7 @@ import Prelude (Bool(..), Char, Maybe(..), Monad(..), Int,
5151 fromIntegral, otherwise)
5252import Data.Bits ((.&.))
5353import Data.Text.Internal (Text(..))
54+import Data.Text.Private (runText)
5455import Data.Text.UnsafeChar (ord, unsafeChr, unsafeWrite)
5556import Data.Text.UnsafeShift (shiftL, shiftR)
5657import qualified Data.Text.Array as A
@@ -94,22 +95,22 @@ reverseStream (Text arr off len) = Stream next (off+len-1) (maxSize len)
9495
9596-- | /O(n)/ Convert a 'Stream Char' into a 'Text'.
9697unstream :: Stream Char -> Text
97−unstream (Stream next0 s0 len) = I.textP (P.fst a) 0 (P.snd a)
98+unstream (Stream next0 s0 len) = a
9899 where
99− a = A.run2 (A.new mlen >>= \arr -> outer arr mlen s0 0)
100+ a = runText (\done -> A.new mlen >>= \arr -> outer done arr mlen s0 0)
100101 where mlen = upperBound 4 len
101− outer arr top = loop
102+ outer done arr top = loop
102103 where
103104 loop !s !i =
104105 case next0 s of
105− Done -> return (arr, i)
106+ Done -> done arr i
106107 Skip s' -> loop s' i
107108 Yield x s'
108109 | j >= top -> {-# SCC "unstream/resize" #-} do
109110 let top' = (top + 1) `shiftL` 1
110111 arr' <- A.new top'
111112 A.copyM arr' 0 arr 0 top
112− outer arr' top' s i
113+ outer done arr' top' s i
113114 | otherwise -> do d <- unsafeWrite arr i x
114115 loop s' (i+d)
115116 where j | ord x < 0x10000 = i