@@ -51,6 +51,7 @@ import Prelude (Bool(..), Char, Maybe(..), Monad(..), Int,
51 fromIntegral, otherwise)
51 fromIntegral, otherwise)
52import Data.Bits ((.&.))
52import Data.Bits ((.&.))
53import Data.Text.Internal (Text(..))
53import Data.Text.Internal (Text(..))
54+import Data.Text.Private (runText)
54import Data.Text.UnsafeChar (ord, unsafeChr, unsafeWrite)
55import Data.Text.UnsafeChar (ord, unsafeChr, unsafeWrite)
55import Data.Text.UnsafeShift (shiftL, shiftR)
56import Data.Text.UnsafeShift (shiftL, shiftR)
56import qualified Data.Text.Array as A
57import qualified Data.Text.Array as A
@@ -94,22 +95,22 @@ reverseStream (Text arr off len) = Stream next (off+len-1) (maxSize len)
95-- | /O(n)/ Convert a 'Stream Char' into a 'Text'.
96-- | /O(n)/ Convert a 'Stream Char' into a 'Text'.
96unstream :: Stream Char -> Text
97unstream :: 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
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)
100 where mlen = upperBound 4 len
101 where mlen = upperBound 4 len
101− outer arr top = loop
102+ outer done arr top = loop
103 loop !s !i =
104 loop !s !i =
104 case next0 s of
105 case next0 s of
105− Done -> return (arr, i)
106+ Done -> done arr i
106 Skip s' -> loop s' i
107 Skip s' -> loop s' i
107 Yield x s'
108 Yield x s'
108 | j >= top -> {-# SCC "unstream/resize" #-} do
109 | j >= top -> {-# SCC "unstream/resize" #-} do
109 let top' = (top + 1) `shiftL` 1
110 let top' = (top + 1) `shiftL` 1
110 arr' <- A.new top'
111 arr' <- A.new top'
111 A.copyM arr' 0 arr 0 top
112 A.copyM arr' 0 arr 0 top
112− outer arr' top' s i
113+ outer done arr' top' s i
113 | otherwise -> do d <- unsafeWrite arr i x
114 | otherwise -> do d <- unsafeWrite arr i x
114 loop s' (i+d)
115 loop s' (i+d)
115 where j | ord x < 0x10000 = i
116 where j | ord x < 0x10000 = i