on master help sign in
unstream: Fine-tune the continuation handling
commitae1cccb2095e2291fa1fe5127122dac3180284d2 authorBryan O'Sullivan <bos@serpentine.com> dateTue 19 Jun 2012, 01:08 (14 years ago) parentd651007
1 file changed+6−4
Data/Text/Fusion.hs+6−4
Data/Text/Fusion.hs+6−4
@@ -97,10 +97,12 @@ reverseStream (Text arr off len) = Stream next (off+len-1) (maxSize len)
9797unstream :: Stream Char -> Text
9898unstream (Stream next0 s0 len) = a
9999 where
100− a = runText (\done -> A.new mlen >>= \arr -> outer done arr mlen s0 0)
100+ a = runText (\done -> A.new mlen >>= \arr -> first done arr mlen s0 0)
101101 where mlen = upperBound 4 len
102− outer done arr top = loop
103− where
102+ first done = outer
103+ where
104+ outer arr top = loop
105+ where
104106 loop !s !i =
105107 case next0 s of
106108 Done -> done arr i
@@ -110,7 +112,7 @@ unstream (Stream next0 s0 len) = a
110112 let top' = (top + 1) `shiftL` 1
111113 arr' <- A.new top'
112114 A.copyM arr' 0 arr 0 top
113− outer done arr' top' s i
115+ outer arr' top' s i
114116 | otherwise -> do d <- unsafeWrite arr i x
115117 loop s' (i+d)
116118 where j | ord x < 0x10000 = i