on master help sign in
Clean up whitespace
c237bb7Duncan Coutts
Text.hs+43−43
@@ -43,16 +43,16 @@ instance Monoid Text where
43 mempty = empty
43 mempty = empty
44 mappend = append
44 mappend = append
45 mconcat = concat
45 mconcat = concat
46−
47
46
48−
47+
48+
49-- -----------------------------------------------------------------------------
49-- -----------------------------------------------------------------------------
50-- * Conversion to/from 'Text'
50-- * Conversion to/from 'Text'
51
51
52-- | /O(n)/ Convert a String into a Text.
52-- | /O(n)/ Convert a String into a Text.
53--
53--
54−-- This function is subject to array fusion, so calling other fusible
54+-- This function is subject to array fusion, so calling other fusible
55−-- function(s) on a packed string will only cause one 'Text' to be written
55+-- function(s) on a packed string will only cause one 'Text' to be written
56-- out at the end of the pipeline, instead of one before and one after.
56-- out at the end of the pipeline, instead of one before and one after.
57pack :: String -> Text
57pack :: String -> Text
58pack str = (unstream (stream_list str))
58pack str = (unstream (stream_list str))
@@ -62,7 +62,7 @@ pack str = (unstream (stream_list str))
62 next [] = S.Done
62 next [] = S.Done
63 next (x:xs) = S.Yield x xs
63 next (x:xs) = S.Yield x xs
64{-# INLINE [1] pack #-}
64{-# INLINE [1] pack #-}
65−-- TODO: Has to do validation! -- No, it doesn't, the
65+-- TODO: Has to do validation! -- No, it doesn't, the
66
66
67-- | /O(n)/ Convert a Text into a String.
67-- | /O(n)/ Convert a Text into a String.
68-- Subject to array fusion.
68-- Subject to array fusion.
@@ -92,32 +92,32 @@ decode enc bs = unstream (stream_bs enc bs)
92{-# INLINE decode #-}
92{-# INLINE decode #-}
93
93
94encode :: Encoding -> Text -> ByteString
94encode :: Encoding -> Text -> ByteString
95−encode enc txt = unstream_bs (restream enc (stream txt))
95+encode enc txt = unstream_bs (restream enc (stream txt))
96{-# INLINE encode #-}
96{-# INLINE encode #-}
97
97
98-- -----------------------------------------------------------------------------
98-- -----------------------------------------------------------------------------
99-- * Basic functions
99-- * Basic functions
100
100
101−-- | /O(n)/ Adds a character to the front of a 'Text'. This function is more
101+-- | /O(n)/ Adds a character to the front of a 'Text'. This function is more
102-- costly than its 'List' counterpart because it requires copying a new array.
102-- costly than its 'List' counterpart because it requires copying a new array.
103-- Subject to array fusion.
103-- Subject to array fusion.
104cons :: Char -> Text -> Text
104cons :: Char -> Text -> Text
105cons c t = unstream (S.cons c (stream t))
105cons c t = unstream (S.cons c (stream t))
106{-# INLINE cons #-}
106{-# INLINE cons #-}
107
107
108−-- | /O(n)/ Adds a character to the end of a 'Text'. This copies the entire
108+-- | /O(n)/ Adds a character to the end of a 'Text'. This copies the entire
109-- array in the process.
109-- array in the process.
110-- Subject to array fusion.
110-- Subject to array fusion.
111snoc :: Text -> Char -> Text
111snoc :: Text -> Char -> Text
112snoc t c = unstream (S.snoc (stream t) c)
112snoc t c = unstream (S.snoc (stream t) c)
113{-# INLINE snoc #-}
113{-# INLINE snoc #-}
114
114
115−-- | /O(n)/ Appends one Text to the other by copying both of them into a new
115+-- | /O(n)/ Appends one Text to the other by copying both of them into a new
116−-- Text.
116+-- Text.
117-- Subject to array fusion
117-- Subject to array fusion
118append :: Text -> Text -> Text
118append :: Text -> Text -> Text
119append (Text arr1 off1 len1) (Text arr2 off2 len2) = Text (runSTUArray x) 0 len
119append (Text arr1 off1 len1) (Text arr2 off2 len2) = Text (runSTUArray x) 0 len
120− where
120+ where
121 len = len1+len2
121 len = len1+len2
122 x = do
122 x = do
123 arr <- unsafeNewArray_ (0,len-1) :: ST s (STUArray s Int Word16)
123 arr <- unsafeNewArray_ (0,len-1) :: ST s (STUArray s Int Word16)
@@ -126,13 +126,13 @@ append (Text arr1 off1 len1) (Text arr2 off2 len2) = Text (runSTUArray x) 0 len
126 return arr
126 return arr
127 where
127 where
128 copy arr i max arr' j
128 copy arr i max arr' j
129− | i >= max = return ()
129+ | i >= max = return ()
130− | otherwise = do unsafeWrite arr' j (arr `unsafeAt` i)
130+ | otherwise = do unsafeWrite arr' j (arr `unsafeAt` i)
131 copy arr (i+1) max arr' (j+1)
131 copy arr (i+1) max arr' (j+1)
132{-# INLINE append #-}
132{-# INLINE append #-}
133
133
134{-# RULES
134{-# RULES
135−"TEXT append -> fused" [~1] forall t1 t2.
135+"TEXT append -> fused" [~1] forall t1 t2.
136 append t1 t2 = unstream (S.append (stream t1) (stream t2))
136 append t1 t2 = unstream (S.append (stream t1) (stream t2))
137"TEXT append -> unfused" [1] forall t1 t2.
137"TEXT append -> unfused" [1] forall t1 t2.
138 unstream (S.append (stream t1) (stream t2)) = append t1 t2
138 unstream (S.append (stream t1) (stream t2)) = append t1 t2
@@ -147,7 +147,7 @@ head t = S.head (stream t)
147-- | /O(n)/ Returns the last character of a Text, which must be non-empty.
147-- | /O(n)/ Returns the last character of a Text, which must be non-empty.
148-- Subject to array fusion.
148-- Subject to array fusion.
149last :: Text -> Char
149last :: Text -> Char
150−last (Text arr off len)
150+last (Text arr off len)
151 | len <= 0 = errorEmptyList "last"
151 | len <= 0 = errorEmptyList "last"
152 | n < 0xDC00 || n > 0xDFFF = unsafeChr n
152 | n < 0xDC00 || n > 0xDFFF = unsafeChr n
153 | otherwise = U16.chr2 n0 n
153 | otherwise = U16.chr2 n0 n
@@ -156,7 +156,7 @@ last (Text arr off len)
156 n0 = unsafeAt arr (off+len-2)
156 n0 = unsafeAt arr (off+len-2)
157{-# INLINE [1] last #-}
157{-# INLINE [1] last #-}
158
158
159−{-# RULES
159+{-# RULES
160"TEXT last -> fused" [~1] forall t.
160"TEXT last -> fused" [~1] forall t.
161 last t = S.last (stream t)
161 last t = S.last (stream t)
162"TEXT last -> unfused" [1] forall t.
162"TEXT last -> unfused" [1] forall t.
@@ -166,7 +166,7 @@ last (Text arr off len)
166
166
167-- | /O(1)/ Returns all characters after the head of a Text, which must
167-- | /O(1)/ Returns all characters after the head of a Text, which must
168-- be non-empty.
168-- be non-empty.
169−-- Subject to array fusion.
169+-- Subject to array fusion.
170tail :: Text -> Text
170tail :: Text -> Text
171tail (Text arr off len)
171tail (Text arr off len)
172 | len <= 0 = errorEmptyList "tail"
172 | len <= 0 = errorEmptyList "tail"
@@ -178,10 +178,10 @@ tail (Text arr off len)
178
178
179
179
180
180
181−-- | /O(1)/ Returns all but the last character of a Text, which
181+-- | /O(1)/ Returns all but the last character of a Text, which
182-- must be non-empty.
182-- must be non-empty.
183-- Subject to array fusion.
183-- Subject to array fusion.
184−init :: Text -> Text
184+init :: Text -> Text
185init (Text arr off len) | len <= 0 = errorEmptyList "init"
185init (Text arr off len) | len <= 0 = errorEmptyList "init"
186 | n >= 0xDC00 && n <= 0xDFFF = Text arr off (len-2)
186 | n >= 0xDC00 && n <= 0xDFFF = Text arr off (len-2)
187 | otherwise = Text arr off (len-1)
187 | otherwise = Text arr off (len-1)
@@ -211,21 +211,21 @@ length t = S.length (stream t)
211-- -----------------------------------------------------------------------------
211-- -----------------------------------------------------------------------------
212-- * Transformations
212-- * Transformations
213-- | /O(n)/ 'map' @f @xs is the Text obtained by applying @f@ to each
213-- | /O(n)/ 'map' @f @xs is the Text obtained by applying @f@ to each
214−-- element of @xs@.
214+-- element of @xs@.
215-- Subject to array fusion.
215-- Subject to array fusion.
216map :: (Char -> Char) -> Text -> Text
216map :: (Char -> Char) -> Text -> Text
217map f t = unstream (S.map f (stream t))
217map f t = unstream (S.map f (stream t))
218{-# INLINE [1] map #-}
218{-# INLINE [1] map #-}
219
219
220−-- | /O(n)/ The 'intersperse' function takes a character and places it between
220+-- | /O(n)/ The 'intersperse' function takes a character and places it between
221-- the characters of a Text.
221-- the characters of a Text.
222-- Subject to array fusion.
222-- Subject to array fusion.
223intersperse :: Char -> Text -> Text
223intersperse :: Char -> Text -> Text
224intersperse c t = unstream (S.intersperse c (stream t))
224intersperse c t = unstream (S.intersperse c (stream t))
225{-# INLINE intersperse #-}
225{-# INLINE intersperse #-}
226
226
227−-- | /O(n)/ The 'transpose' function transposes the rows and columns of its
227+-- | /O(n)/ The 'transpose' function transposes the rows and columns of its
228−-- Text argument. Note that this function uses pack, unpack, and the 'List'
228+-- Text argument. Note that this function uses pack, unpack, and the 'List'
229-- version of transpose and is thus not very efficient.
229-- version of transpose and is thus not very efficient.
230transpose :: [Text] -> [Text]
230transpose :: [Text] -> [Text]
231transpose ts = P.map pack (L.transpose (P.map unpack ts))
231transpose ts = P.map pack (L.transpose (P.map unpack ts))
@@ -233,7 +233,7 @@ transpose ts = P.map pack (L.transpose (P.map unpack ts))
233-- -----------------------------------------------------------------------------
233-- -----------------------------------------------------------------------------
234-- * Reducing 'Text's (folds)
234-- * Reducing 'Text's (folds)
235
235
236−-- | 'foldl', applied to a binary operator, a starting value (typically the
236+-- | 'foldl', applied to a binary operator, a starting value (typically the
237-- left-identity of the operator), and a Text, reduces the Text using the
237-- left-identity of the operator), and a Text, reduces the Text using the
238-- binary operator, from left to right.
238-- binary operator, from left to right.
239-- Subject to array fusion.
239-- Subject to array fusion.
@@ -247,7 +247,7 @@ foldl' :: (b -> Char -> b) -> b -> Text -> b
247foldl' f z t = S.foldl' f z (stream t)
247foldl' f z t = S.foldl' f z (stream t)
248{-# INLINE foldl' #-}
248{-# INLINE foldl' #-}
249
249
250−-- | 'foldl1' is a variant of 'foldl' that has no starting value argument,
250+-- | 'foldl1' is a variant of 'foldl' that has no starting value argument,
251-- and thus must be applied to non-empty 'Text's.
251-- and thus must be applied to non-empty 'Text's.
252-- Subject to array fusion.
252-- Subject to array fusion.
253foldl1 :: (Char -> Char -> Char) -> Text -> Char
253foldl1 :: (Char -> Char -> Char) -> Text -> Char
@@ -260,7 +260,7 @@ foldl1' :: (Char -> Char -> Char) -> Text -> Char
260foldl1' f t = S.foldl1' f (stream t)
260foldl1' f t = S.foldl1' f (stream t)
261{-# INLINE foldl1' #-}
261{-# INLINE foldl1' #-}
262
262
263−-- | 'foldr', applied to a binary operator, a starting value (typically the
263+-- | 'foldr', applied to a binary operator, a starting value (typically the
264-- right-identity of the operator), and a Text, reduces the Text using the
264-- right-identity of the operator), and a Text, reduces the Text using the
265-- binary operator, from right to left.
265-- binary operator, from right to left.
266-- Subject to array fusion.
266-- Subject to array fusion.
@@ -268,7 +268,7 @@ foldr :: (Char -> b -> b) -> b -> Text -> b
268foldr f z t = S.foldr f z (stream t)
268foldr f z t = S.foldr f z (stream t)
269{-# INLINE foldr #-}
269{-# INLINE foldr #-}
270
270
271−-- | 'foldr1' is a variant of 'foldr' that has no starting value argument,
271+-- | 'foldr1' is a variant of 'foldr' that has no starting value argument,
272-- and thust must be applied to non-empty 'Text's.
272-- and thust must be applied to non-empty 'Text's.
273-- Subject to array fusion.
273-- Subject to array fusion.
274foldr1 :: (Char -> Char -> Char) -> Text -> Char
274foldr1 :: (Char -> Char -> Char) -> Text -> Char
@@ -283,10 +283,10 @@ concat :: [Text] -> Text
283concat ts = unstream (S.concat (L.map stream ts))
283concat ts = unstream (S.concat (L.map stream ts))
284{-# INLINE concat #-}
284{-# INLINE concat #-}
285
285
286−-- | Map a function over a Text that results in a Text and concatenate the
286+-- | Map a function over a Text that results in a Text and concatenate the
287−-- results. This function is subject to array fusion, and note that if in
287+-- results. This function is subject to array fusion, and note that if in
288−-- 'concatMap' @f @xs, @f@ is defined in terms of fusible functions it will
288+-- 'concatMap' @f @xs, @f@ is defined in terms of fusible functions it will
289−-- also be fusible.
289+-- also be fusible.
290concatMap :: (Char -> Text) -> Text -> Text
290concatMap :: (Char -> Text) -> Text -> Text
291concatMap f t = unstream (S.concatMap (stream . f) (stream t))
291concatMap f t = unstream (S.concatMap (stream . f) (stream t))
292{-# INLINE concatMap #-}
292{-# INLINE concatMap #-}
@@ -303,13 +303,13 @@ all :: (Char -> Bool) -> Text -> Bool
303all p t = S.all p (stream t)
303all p t = S.all p (stream t)
304{-# INLINE all #-}
304{-# INLINE all #-}
305
305
306−-- | /O(n)/ 'maximum' returns the maximum value from a 'Text', which must be
306+-- | /O(n)/ 'maximum' returns the maximum value from a 'Text', which must be
307-- non-empty. Subject to array fusion.
307-- non-empty. Subject to array fusion.
308maximum :: Text -> Char
308maximum :: Text -> Char
309maximum t = S.maximum (stream t)
309maximum t = S.maximum (stream t)
310{-# INLINE maximum #-}
310{-# INLINE maximum #-}
311
311
312−-- | /O(n)/ 'minimum' returns the minimum value from a 'Text', which must be
312+-- | /O(n)/ 'minimum' returns the minimum value from a 'Text', which must be
313-- non-empty. Subject to array fusion.
313-- non-empty. Subject to array fusion.
314minimum :: Text -> Char
314minimum :: Text -> Char
315minimum t = S.minimum (stream t)
315minimum t = S.minimum (stream t)
@@ -350,15 +350,15 @@ take :: Int -> Text -> Text
350take n (Text arr off len) = Text arr off (loop off 0)
350take n (Text arr off len) = Text arr off (loop off 0)
351 where
351 where
352 end = off+len
352 end = off+len
353− loop !i !count
353+ loop !i !count
354 | i >= end || count >= n = i - off
354 | i >= end || count >= n = i - off
355− | c < 0xD800 || c > 0xDBFF = loop (i+1) (count+1)
355+ | c < 0xD800 || c > 0xDBFF = loop (i+1) (count+1)
356 | otherwise = loop (i+2) (count+1)
356 | otherwise = loop (i+2) (count+1)
357 where
357 where
358 c = arr `unsafeAt` i
358 c = arr `unsafeAt` i
359{-# INLINE [1] take #-}
359{-# INLINE [1] take #-}
360
360
361−{-# RULES
361+{-# RULES
362"TEXT take -> fused" [~1] forall n t.
362"TEXT take -> fused" [~1] forall n t.
363 take n t = unstream (S.take n (stream t))
363 take n t = unstream (S.take n (stream t))
364"TEXT take -> unfused" [1] forall n t.
364"TEXT take -> unfused" [1] forall n t.
@@ -381,7 +381,7 @@ drop n (Text arr off len) = (Text arr newOff newLen)
381 c = arr `unsafeAt` i
381 c = arr `unsafeAt` i
382{-# INLINE [1] drop #-}
382{-# INLINE [1] drop #-}
383
383
384−{-# RULES
384+{-# RULES
385"TEXT drop -> fused" [~1] forall n t.
385"TEXT drop -> fused" [~1] forall n t.
386 drop n t = unstream (S.drop n (stream t))
386 drop n t = unstream (S.drop n (stream t))
387"TEXT drop -> unfused" [1] forall n t.
387"TEXT drop -> unfused" [1] forall n t.
@@ -398,7 +398,7 @@ dropWhile :: (Char -> Bool) -> Text -> Text
398dropWhile p t = unstream (S.dropWhile p (stream t))
398dropWhile p t = unstream (S.dropWhile p (stream t))
399
399
400-- ----------------------------------------------------------------------------
400-- ----------------------------------------------------------------------------
401−-- * Searching
401+-- * Searching
402
402
403-------------------------------------------------------------------------------
403-------------------------------------------------------------------------------
404-- ** Searching by equality
404-- ** Searching by equality
@@ -455,22 +455,22 @@ elemIndex c t = S.elemIndex c (stream t)
455zipWith :: (Char -> Char -> Char) -> Text -> Text -> Text
455zipWith :: (Char -> Char -> Char) -> Text -> Text -> Text
456zipWith f t1 t2 = unstream (S.zipWith f (stream t1) (stream t2))
456zipWith f t1 t2 = unstream (S.zipWith f (stream t1) (stream t2))
457
457
458−-- File I/O
458+-- File I/O
459
459
460readFile :: Encoding -> FilePath -> IO Text
460readFile :: Encoding -> FilePath -> IO Text
461−readFile enc f = B.readFile f >>= return . unstream . stream_bs enc
461+readFile enc f = B.readFile f >>= return . unstream . stream_bs enc
462{-# INLINE [1] readFile #-}
462{-# INLINE [1] readFile #-}
463
463
464words :: Text -> [Text]
464words :: Text -> [Text]
465words (Text arr off len) = loop0 off off
465words (Text arr off len) = loop0 off off
466 where
466 where
467− loop0 start n
467+ loop0 start n
468 | isSpace (unsafeChr c) = if start == n
468 | isSpace (unsafeChr c) = if start == n
469− then loop0 (start+1) (start+1)
469+ then loop0 (start+1) (start+1)
470 else (Text arr start (n-start)):loop0 (n+1) (n+1)
470 else (Text arr start (n-start)):loop0 (n+1) (n+1)
471 | n < (off+len) = loop0 start (n+1)
471 | n < (off+len) = loop0 start (n+1)
472 | otherwise = if start == n
472 | otherwise = if start == n
473− then []
473+ then []
474 else [(Text arr start (n-start))]
474 else [(Text arr start (n-start))]
475 where
475 where
476 c = arr `unsafeAt` n
476 c = arr `unsafeAt` n
Text/Fusion.hs+72−72
@@ -63,7 +63,7 @@ unstream :: Stream Char -> Text
63unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
63unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
64 where
64 where
65 x :: ((UArray Int Word16),Int)
65 x :: ((UArray Int Word16),Int)
66− x = runST ((unsafeNewArray_ (0,len+1) :: ST s (STUArray s Int Word16))
66+ x = runST ((unsafeNewArray_ (0,len+1) :: ST s (STUArray s Int Word16))
67 >>= (\arr -> loop arr 0 (len+1) s0))
67 >>= (\arr -> loop arr 0 (len+1) s0))
68 loop arr !i !max !s
68 loop arr !i !max !s
69 | i + 1 > max = do arr' <- unsafeNewArray_ (0,max*2)
69 | i + 1 > max = do arr' <- unsafeNewArray_ (0,max*2)
@@ -80,7 +80,7 @@ unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
80 | otherwise -> do
80 | otherwise -> do
81 unsafeWrite arr i l
81 unsafeWrite arr i l
82 unsafeWrite arr (i + 1) r
82 unsafeWrite arr (i + 1) r
83− loop arr (i+2) max s'
83+ loop arr (i+2) max s'
84 where
84 where
85 n :: Int
85 n :: Int
86 n = ord x
86 n = ord x
@@ -93,13 +93,13 @@ unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
93{-# INLINE [0] unstream #-}
93{-# INLINE [0] unstream #-}
94
94
95
95
96−copy src dest = (do
96+copy src dest = (do
97 (_,max) <- getBounds src
97 (_,max) <- getBounds src
98 copy_loop 0 max)
98 copy_loop 0 max)
99 where
99 where
100− copy_loop !i !max
100+ copy_loop !i !max
101 | i > max = return ()
101 | i > max = return ()
102− | otherwise = do v <- unsafeRead src i
102+ | otherwise = do v <- unsafeRead src i
103 unsafeWrite dest i v
103 unsafeWrite dest i v
104 copy_loop (i+1) max
104 copy_loop (i+1) max
105
105
@@ -113,7 +113,7 @@ eq (Stream next1 s1 _) (Stream next2 s2 _) = compare (next1 s1) (next2 s2)
113 compare (Skip s1') (Skip s2') = compare (next1 s1') (next2 s2')
113 compare (Skip s1') (Skip s2') = compare (next1 s1') (next2 s2')
114 compare (Skip s1') x2 = compare (next1 s1') x2
114 compare (Skip s1') x2 = compare (next1 s1') x2
115 compare x1 (Skip s2') = compare x1 (next2 s2')
115 compare x1 (Skip s2') = compare x1 (next2 s2')
116− compare (Yield x1 s1') (Yield x2 s2') = x1 == x2 &&
116+ compare (Yield x1 s1') (Yield x2 s2') = x1 == x2 &&
117 compare (next1 s1') (next2 s2')
117 compare (next1 s1') (next2 s2')
118{-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
118{-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
119
119
@@ -123,12 +123,12 @@ stream_bs :: Encoding -> ByteString -> Stream Char
123stream_bs ASCII bs = Stream next 0 (B.length bs)
123stream_bs ASCII bs = Stream next 0 (B.length bs)
124 where
124 where
125 {-# INLINE next #-}
125 {-# INLINE next #-}
126− next i
126+ next i
127 | i >= l = Done
127 | i >= l = Done
128 | otherwise = Yield (unsafeChr8 x1) (i+1)
128 | otherwise = Yield (unsafeChr8 x1) (i+1)
129 where
129 where
130 l = B.length bs
130 l = B.length bs
131− x1 = B.index bs i
131+ x1 = B.index bs i
132stream_bs Utf8 bs = Stream next 0 (B.length bs)
132stream_bs Utf8 bs = Stream next 0 (B.length bs)
133 where
133 where
134 {-# INLINE next #-}
134 {-# INLINE next #-}
@@ -145,11 +145,11 @@ stream_bs Utf8 bs = Stream next 0 (B.length bs)
145 x2 = index (i + 1)
145 x2 = index (i + 1)
146 x3 = index (i + 2)
146 x3 = index (i + 2)
147 x4 = index (i + 3)
147 x4 = index (i + 3)
148− index = B.index bs
148+ index = B.index bs
149stream_bs Utf16LE bs = Stream next 0 (B.length bs)
149stream_bs Utf16LE bs = Stream next 0 (B.length bs)
150 where
150 where
151 {-# INLINE next #-}
151 {-# INLINE next #-}
152− next i
152+ next i
153 | i >= l = Done
153 | i >= l = Done
154 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
154 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
155 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
155 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
@@ -159,12 +159,12 @@ stream_bs Utf16LE bs = Stream next 0 (B.length bs)
159 x1 = (shiftL (index (i + 1)) 8) + (index i)
159 x1 = (shiftL (index (i + 1)) 8) + (index i)
160 x2 :: Word16
160 x2 :: Word16
161 x2 = (shiftL (index (i + 3)) 8) + (index (i + 2))
161 x2 = (shiftL (index (i + 3)) 8) + (index (i + 2))
162− l = B.length bs
162+ l = B.length bs
163 index = fromIntegral . B.index bs :: Int -> Word16
163 index = fromIntegral . B.index bs :: Int -> Word16
164stream_bs Utf16BE bs = Stream next 0 (B.length bs)
164stream_bs Utf16BE bs = Stream next 0 (B.length bs)
165 where
165 where
166 {-# INLINE next #-}
166 {-# INLINE next #-}
167− next i
167+ next i
168 | i >= l = Done
168 | i >= l = Done
169 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
169 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
170 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
170 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
@@ -179,7 +179,7 @@ stream_bs Utf16BE bs = Stream next 0 (B.length bs)
179stream_bs Utf32BE bs = Stream next 0 (B.length bs)
179stream_bs Utf32BE bs = Stream next 0 (B.length bs)
180 where
180 where
181 {-# INLINE next #-}
181 {-# INLINE next #-}
182− next i
182+ next i
183 | i >= l = Done
183 | i >= l = Done
184 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
184 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
185 | otherwise = error "bsStream: bad UTF-32BE stream"
185 | otherwise = error "bsStream: bad UTF-32BE stream"
@@ -194,7 +194,7 @@ stream_bs Utf32BE bs = Stream next 0 (B.length bs)
194stream_bs Utf32LE bs = Stream next 0 (B.length bs)
194stream_bs Utf32LE bs = Stream next 0 (B.length bs)
195 where
195 where
196 {-# INLINE next #-}
196 {-# INLINE next #-}
197− next i
197+ next i
198 | i >= l = Done
198 | i >= l = Done
199 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
199 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
200 | otherwise = error "bsStream: bad UTF-32LE stream"
200 | otherwise = error "bsStream: bad UTF-32LE stream"
@@ -217,14 +217,14 @@ restream ASCII (Stream next0 s0 len) = Stream next s0 (len*2)
217 Skip s' -> Skip s'
217 Skip s' -> Skip s'
218 Yield x xs -> Yield x' xs
218 Yield x xs -> Yield x' xs
219 where x' = fromIntegral (ord x) :: Word8
219 where x' = fromIntegral (ord x) :: Word8
220−restream Utf8 (Stream next0 s0 len) =
220+restream Utf8 (Stream next0 s0 len) =
221 Stream next ((Just s0) :!: Nothing :!: Nothing :!: Nothing) (len*2)
221 Stream next ((Just s0) :!: Nothing :!: Nothing :!: Nothing) (len*2)
222 where
222 where
223 {-# INLINE next #-}
223 {-# INLINE next #-}
224− next ((Just s) :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
224+ next ((Just s) :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
225 Done -> Done
225 Done -> Done
226 Skip s' -> Skip ((Just s') :!: Nothing :!: Nothing :!: Nothing)
226 Skip s' -> Skip ((Just s') :!: Nothing :!: Nothing :!: Nothing)
227− Yield x xs
227+ Yield x xs
228 | n <= 0x7F -> Yield c ((Just xs) :!: Nothing :!: Nothing :!: Nothing)
228 | n <= 0x7F -> Yield c ((Just xs) :!: Nothing :!: Nothing :!: Nothing)
229 | n <= 0x07FF -> Yield (fst c2) ((Just xs) :!: (Just $ snd c2) :!: Nothing :!: Nothing)
229 | n <= 0x07FF -> Yield (fst c2) ((Just xs) :!: (Just $ snd c2) :!: Nothing :!: Nothing)
230 | n <= 0xFFFF -> Yield (fst3 c3) ((Just xs) :!: (Just $ snd3 c3) :!: (Just $ trd3 c3) :!: Nothing)
230 | n <= 0xFFFF -> Yield (fst3 c3) ((Just xs) :!: (Just $ snd3 c3) :!: (Just $ trd3 c3) :!: Nothing)
@@ -234,7 +234,7 @@ restream Utf8 (Stream next0 s0 len) =
234 c = fromIntegral n
234 c = fromIntegral n
235 c2 = U8.ord2 x
235 c2 = U8.ord2 x
236 c3 = U8.ord3 x
236 c3 = U8.ord3 x
237− c4 = U8.ord4 x
237+ c4 = U8.ord4 x
238 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
238 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
239 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
239 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
240 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
240 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
@@ -242,7 +242,7 @@ restream Utf16BE (Stream next0 s0 len) =
242 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
242 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
243 where
243 where
244 {-# INLINE next #-}
244 {-# INLINE next #-}
245− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
245+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
246 Done -> Done
246 Done -> Done
247 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
247 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
248 Yield x xs
248 Yield x xs
@@ -250,12 +250,12 @@ restream Utf16BE (Stream next0 s0 len) =
250 | otherwise -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
250 | otherwise -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
251 where
251 where
252 n = ord x
252 n = ord x
253− n1 = n - 0x10000
253+ n1 = n - 0x10000
254 c1 = fromIntegral (shiftR n1 18 + 0xD8)
254 c1 = fromIntegral (shiftR n1 18 + 0xD8)
255− c2 = fromIntegral (shiftR n1 10)
255+ c2 = fromIntegral (shiftR n1 10)
256 n2 = n1 .&. 0x3FF
256 n2 = n1 .&. 0x3FF
257− c3 = fromIntegral (shiftR n2 8 + 0xDC)
257+ c3 = fromIntegral (shiftR n2 8 + 0xDC)
258− c4 = fromIntegral n2
258+ c4 = fromIntegral n2
259 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
259 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
260 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
260 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
261 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
261 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
@@ -263,7 +263,7 @@ restream Utf16LE (Stream next0 s0 len) =
263 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
263 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
264 where
264 where
265 {-# INLINE next #-}
265 {-# INLINE next #-}
266− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
266+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
267 Done -> Done
267 Done -> Done
268 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
268 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
269 Yield x xs
269 Yield x xs
@@ -271,20 +271,20 @@ restream Utf16LE (Stream next0 s0 len) =
271 | otherwise -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
271 | otherwise -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
272 where
272 where
273 n = ord x
273 n = ord x
274− n1 = n - 0x10000
274+ n1 = n - 0x10000
275 c2 = fromIntegral (shiftR n1 18 + 0xD8)
275 c2 = fromIntegral (shiftR n1 18 + 0xD8)
276− c1 = fromIntegral (shiftR n1 10)
276+ c1 = fromIntegral (shiftR n1 10)
277 n2 = n1 .&. 0x3FF
277 n2 = n1 .&. 0x3FF
278− c4 = fromIntegral (shiftR n2 8 + 0xDC)
278+ c4 = fromIntegral (shiftR n2 8 + 0xDC)
279− c3 = fromIntegral n2
279+ c3 = fromIntegral n2
280 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
280 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
281 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
281 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
282 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
282 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
283−restream Utf32BE (Stream next0 s0 len) =
283+restream Utf32BE (Stream next0 s0 len) =
284 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
284 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
285 where
285 where
286 {-# INLINE next #-}
286 {-# INLINE next #-}
287− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
287+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
288 Done -> Done
288 Done -> Done
289 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
289 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
290 Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
290 Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
@@ -297,11 +297,11 @@ restream Utf32BE (Stream next0 s0 len) =
297 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
297 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
298 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
298 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
299 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
299 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
300−restream Utf32LE (Stream next0 s0 len) =
300+restream Utf32LE (Stream next0 s0 len) =
301 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
301 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
302 where
302 where
303 {-# INLINE next #-}
303 {-# INLINE next #-}
304− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
304+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
305 Done -> Done
305 Done -> Done
306 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
306 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
307 Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
307 Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
@@ -315,15 +315,15 @@ restream Utf32LE (Stream next0 s0 len) =
315 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
315 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
316 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
316 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
317{-# INLINE restream #-}
317{-# INLINE restream #-}
318−
318+
319
319
320fst3 (x1,_,_) = x1
320fst3 (x1,_,_) = x1
321snd3 (_,x2,_) = x2
321snd3 (_,x2,_) = x2
322trd3 (_,_,x3) = x3
322trd3 (_,_,x3) = x3
323−fst4 (x1,_,_,_) = x1
323+fst4 (x1,_,_,_) = x1
324snd4 (_,x2,_,_) = x2
324snd4 (_,x2,_,_) = x2
325trd4 (_,_,x3,_) = x3
325trd4 (_,_,x3,_) = x3
326−fth4 (_,_,_,x4) = x4
326+fth4 (_,_,_,x4) = x4
327
327
328-- | /O(n)/ Convert a Stream Word8 to a ByteString
328-- | /O(n)/ Convert a Stream Word8 to a ByteString
329unstream_bs :: Stream Word8 -> ByteString
329unstream_bs :: Stream Word8 -> ByteString
@@ -359,13 +359,13 @@ unstream_bs (Stream next s0 len) = unsafePerformIO $ do
359-- ----------------------------------------------------------------------------
359-- ----------------------------------------------------------------------------
360-- * Basic stream functions
360-- * Basic stream functions
361
361
362−-- | /O(n)/ Adds a character to the front of a Stream Char.
362+-- | /O(n)/ Adds a character to the front of a Stream Char.
363cons :: Char -> Stream Char -> Stream Char
363cons :: Char -> Stream Char -> Stream Char
364cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2)
364cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2)
365 where
365 where
366 {-# INLINE next #-}
366 {-# INLINE next #-}
367 next (S2 :!: s) = Yield w (S1 :!: s)
367 next (S2 :!: s) = Yield w (S1 :!: s)
368− next (S1 :!: s) = case next0 s of
368+ next (S1 :!: s) = case next0 s of
369 Done -> Done
369 Done -> Done
370 Skip s' -> Skip (S1 :!: s')
370 Skip s' -> Skip (S1 :!: s')
371 Yield x s' -> Yield x (S1 :!: s')
371 Yield x s' -> Yield x (S1 :!: s')
@@ -385,11 +385,11 @@ snoc (Stream next0 xs0 len) w = Stream next (Just xs0) (len+2)
385
385
386-- | /O(n)/ Appends one Stream to the other.
386-- | /O(n)/ Appends one Stream to the other.
387append :: Stream Char -> Stream Char -> Stream Char
387append :: Stream Char -> Stream Char -> Stream Char
388−append (Stream next0 s01 len1) (Stream next1 s02 len2) =
388+append (Stream next0 s01 len1) (Stream next1 s02 len2) =
389 Stream next (Left s01) (len1 + len2)
389 Stream next (Left s01) (len1 + len2)
390 where
390 where
391 {-# INLINE next #-}
391 {-# INLINE next #-}
392− next (Left s1) = case next0 s1 of
392+ next (Left s1) = case next0 s1 of
393 Done -> Skip (Right s02)
393 Done -> Skip (Right s02)
394 Skip s1' -> Skip (Left s1')
394 Skip s1' -> Skip (Left s1')
395 Yield x s1' -> Yield x (Left s1')
395 Yield x s1' -> Yield x (Left s1')
@@ -403,8 +403,8 @@ append (Stream next0 s01 len1) (Stream next1 s02 len2) =
403-- Subject to array fusion.
403-- Subject to array fusion.
404head :: Stream Char -> Char
404head :: Stream Char -> Char
405head (Stream next s0 len) = loop_head s0
405head (Stream next s0 len) = loop_head s0
406− where
406+ where
407− loop_head !s = case next s of
407+ loop_head !s = case next s of
408 Yield x _ -> x
408 Yield x _ -> x
409 Skip s' -> loop_head s'
409 Skip s' -> loop_head s'
410 Done -> error "head: Empty list"
410 Done -> error "head: Empty list"
@@ -433,7 +433,7 @@ tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1)
433 next (False :!: s) = case next0 s of
433 next (False :!: s) = case next0 s of
434 Done -> error "tail"
434 Done -> error "tail"
435 Skip s' -> Skip (False :!: s')
435 Skip s' -> Skip (False :!: s')
436− Yield _ s' -> Skip (True :!: s')
436+ Yield _ s' -> Skip (True :!: s')
437 next (True :!: s) = case next0 s of
437 next (True :!: s) = case next0 s of
438 Done -> Done
438 Done -> Done
439 Skip s' -> Skip (True :!: s')
439 Skip s' -> Skip (True :!: s')
@@ -441,7 +441,7 @@ tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1)
441{-# INLINE [0] tail #-}
441{-# INLINE [0] tail #-}
442
442
443
443
444−-- | /O(1)/ Returns all but the last character of a Stream Char, which
444+-- | /O(1)/ Returns all but the last character of a Stream Char, which
445-- must be non-empty.
445-- must be non-empty.
446init :: Stream Char -> Stream Char
446init :: Stream Char -> Stream Char
447init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1)
447init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1)
@@ -472,28 +472,28 @@ length :: Stream Char -> Int
472length (Stream next s0 len) = loop_length 0# s0
472length (Stream next s0 len) = loop_length 0# s0
473 where
473 where
474
474
475− loop_length z# !s = case next s of
475+ loop_length z# !s = case next s of
476 Done -> (I# z#)
476 Done -> (I# z#)
477− Skip s' -> loop_length z# s'
477+ Skip s' -> loop_length z# s'
478− Yield _ s' -> loop_length (z# +# 1#) s'
478+ Yield _ s' -> loop_length (z# +# 1#) s'
479{-# INLINE[0] length #-}
479{-# INLINE[0] length #-}
480
480
481-- ----------------------------------------------------------------------------
481-- ----------------------------------------------------------------------------
482-- * Stream transformations
482-- * Stream transformations
483
483
484−-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
484+-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
485−-- @xs@.
485+-- @xs@.
486map :: (Char -> Char) -> Stream Char -> Stream Char
486map :: (Char -> Char) -> Stream Char -> Stream Char
487map f (Stream next0 s0 len) = Stream next s0 len
487map f (Stream next0 s0 len) = Stream next s0 len
488 where
488 where
489 {-# INLINE next #-}
489 {-# INLINE next #-}
490− next !s = case next0 s of
490+ next !s = case next0 s of
491 Done -> Done
491 Done -> Done
492 Skip s' -> Skip s'
492 Skip s' -> Skip s'
493− Yield x s' -> Yield (f x) s'
493+ Yield x s' -> Yield (f x) s'
494{-# INLINE [0] map #-}
494{-# INLINE [0] map #-}
495
495
496−{-#
496+{-#
497 RULES "STREAM map/map fusion" forall f g s.
497 RULES "STREAM map/map fusion" forall f g s.
498 map f (map g s) = map (\x -> f (g x)) s
498 map f (map g s) = map (\x -> f (g x)) s
499 #-}
499 #-}
@@ -517,7 +517,7 @@ intersperse c (Stream next0 s0 len) = Stream next (s0 :!: Nothing :!: S1) len
517-- ----------------------------------------------------------------------------
517-- ----------------------------------------------------------------------------
518-- * Reducing Streams (folds)
518-- * Reducing Streams (folds)
519
519
520−-- | foldl, applied to a binary operator, a starting value (typically the
520+-- | foldl, applied to a binary operator, a starting value (typically the
521-- left-identity of the operator), and a Stream, reduces the Stream using the
521-- left-identity of the operator), and a Stream, reduces the Stream using the
522-- binary operator, from left to right.
522-- binary operator, from left to right.
523foldl :: (b -> Char -> b) -> b -> Stream Char -> b
523foldl :: (b -> Char -> b) -> b -> Stream Char -> b
@@ -539,7 +539,7 @@ foldl' f z0 (Stream next s0 len) = loop_foldl' z0 s0
539 Yield x s' -> loop_foldl' (f z x) s'
539 Yield x s' -> loop_foldl' (f z x) s'
540{-# INLINE [0] foldl' #-}
540{-# INLINE [0] foldl' #-}
541
541
542−-- | foldl1 is a variant of foldl that has no starting value argument,
542+-- | foldl1 is a variant of foldl that has no starting value argument,
543-- and thus must be applied to non-empty Streams.
543-- and thus must be applied to non-empty Streams.
544foldl1 :: (Char -> Char -> Char) -> Stream Char -> Char
544foldl1 :: (Char -> Char -> Char) -> Stream Char -> Char
545foldl1 f (Stream next s0 len) = loop0_foldl1 s0
545foldl1 f (Stream next s0 len) = loop0_foldl1 s0
@@ -568,7 +568,7 @@ foldl1' f (Stream next s0 len) = loop0_foldl1' s0
568 Yield x s' -> loop_foldl1' (f z x) s'
568 Yield x s' -> loop_foldl1' (f z x) s'
569{-# INLINE [0] foldl1' #-}
569{-# INLINE [0] foldl1' #-}
570
570
571−-- | 'foldr', applied to a binary operator, a starting value (typically the
571+-- | 'foldr', applied to a binary operator, a starting value (typically the
572-- right-identity of the operator), and a stream, reduces the stream using the
572-- right-identity of the operator), and a stream, reduces the stream using the
573-- binary operator, from right to left.
573-- binary operator, from right to left.
574foldr :: (Char -> b -> b) -> b -> Stream Char -> b
574foldr :: (Char -> b -> b) -> b -> Stream Char -> b
@@ -580,7 +580,7 @@ foldr f z (Stream next s0 len) = loop_foldr s0
580 Yield x s' -> f x (loop_foldr s')
580 Yield x s' -> f x (loop_foldr s')
581{-# INLINE [0] foldr #-}
581{-# INLINE [0] foldr #-}
582
582
583−-- | foldr1 is a variant of 'foldr' that has no starting value argument,
583+-- | foldr1 is a variant of 'foldr' that has no starting value argument,
584-- and thust must be applied to non-empty streams.
584-- and thust must be applied to non-empty streams.
585-- Subject to array fusion.
585-- Subject to array fusion.
586foldr1 :: (Char -> Char -> Char) -> Stream Char -> Char
586foldr1 :: (Char -> Char -> Char) -> Stream Char -> Char
@@ -596,7 +596,7 @@ foldr1 f (Stream next s0 len) = loop0_foldr1 s0
596 Skip s' -> loop_foldr1 x s'
596 Skip s' -> loop_foldr1 x s'
597 Yield x' s' -> f x (loop_foldr1 x' s')
597 Yield x' s' -> f x (loop_foldr1 x' s')
598{-# INLINE [0] foldr1 #-}
598{-# INLINE [0] foldr1 #-}
599−
599+
600-- ----------------------------------------------------------------------------
600-- ----------------------------------------------------------------------------
601-- ** Special folds
601-- ** Special folds
602
602
@@ -606,7 +606,7 @@ concat = L.foldr append (Stream next Done 0)
606 where
606 where
607 next Done = Done
607 next Done = Done
608
608
609−-- | Map a function over a stream that results in a steram and concatenate the
609+-- | Map a function over a stream that results in a steram and concatenate the
610-- results.
610-- results.
611concatMap :: (Char -> Stream Char) -> Stream Char -> Stream Char
611concatMap :: (Char -> Stream Char) -> Stream Char -> Stream Char
612concatMap f = foldr (append . f) (stream empty)
612concatMap f = foldr (append . f) (stream empty)
@@ -627,14 +627,14 @@ any p (Stream next0 s0 len) = loop_any s0
627all :: (Char -> Bool) -> Stream Char -> Bool
627all :: (Char -> Bool) -> Stream Char -> Bool
628all p (Stream next0 s0 len) = loop_all s0
628all p (Stream next0 s0 len) = loop_all s0
629 where
629 where
630− loop_all !s = case next0 s of
630+ loop_all !s = case next0 s of
631 Done -> True
631 Done -> True
632 Skip s' -> seq s' $ loop_all s'
632 Skip s' -> seq s' $ loop_all s'
633 Yield x s' | p x -> seq s' $ loop_all s'
633 Yield x s' | p x -> seq s' $ loop_all s'
634 | otherwise -> False
634 | otherwise -> False
635
635
636−-- | /O(n)/ maximum returns the maximum value from a stream, which must be
636+-- | /O(n)/ maximum returns the maximum value from a stream, which must be
637−-- non-empty.
637+-- non-empty.
638maximum :: Stream Char -> Char
638maximum :: Stream Char -> Char
639maximum (Stream next0 s0 len) = loop0_maximum s0
639maximum (Stream next0 s0 len) = loop0_maximum s0
640 where
640 where
@@ -648,8 +648,8 @@ maximum (Stream next0 s0 len) = loop0_maximum s0
648 Yield x s'
648 Yield x s'
649 | x > z -> seq s' $ loop_maximum x s'
649 | x > z -> seq s' $ loop_maximum x s'
650 | otherwise -> seq s' $ loop_maximum z s'
650 | otherwise -> seq s' $ loop_maximum z s'
651−
651+
652−-- | /O(n)/ minimum returns the minimum value from a 'Text', which must be
652+-- | /O(n)/ minimum returns the minimum value from a 'Text', which must be
653-- non-empty.
653-- non-empty.
654minimum :: Stream Char -> Char
654minimum :: Stream Char -> Char
655minimum (Stream next0 s0 len) = loop0_minimum s0
655minimum (Stream next0 s0 len) = loop0_minimum s0
@@ -666,8 +666,8 @@ minimum (Stream next0 s0 len) = loop0_minimum s0
666 | otherwise -> seq s' $ loop_minimum z s'
666 | otherwise -> seq s' $ loop_minimum z s'
667
667
668
668
669−
669+
670−
670+
671-- -----------------------------------------------------------------------------
671-- -----------------------------------------------------------------------------
672-- * Building streams
672-- * Building streams
673
673
@@ -694,8 +694,8 @@ unfoldr f s0 = Stream next s0 1
694-- first argument to unfoldrN. This function is more efficient than
694-- first argument to unfoldrN. This function is more efficient than
695-- unfoldr when the maximum length of the result and correct,
695-- unfoldr when the maximum length of the result and correct,
696-- otherwise its complexity performance is similar to 'unfoldr'
696-- otherwise its complexity performance is similar to 'unfoldr'
697−unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char
697+unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char
698−unfoldrN n f s0 = Stream next (0 :!: s0) (n*2)
698+unfoldrN n f s0 = Stream next (0 :!: s0) (n*2)
699 where
699 where
700 {-# INLINE next #-}
700 {-# INLINE next #-}
701 next (z :!: s) = case f s of
701 next (z :!: s) = case f s of
@@ -718,7 +718,7 @@ take n0 (Stream next0 s0 len) = Stream next (n0 :!: s0) len
718 Skip s' -> Skip (n :!: s')
718 Skip s' -> Skip (n :!: s')
719 Yield x s' -> Yield x ((n-1) :!: s')
719 Yield x s' -> Yield x ((n-1) :!: s')
720{-# INLINE [0] take #-}
720{-# INLINE [0] take #-}
721−
721+
722-- | /O(n)/ drop n, applied to a stream, returns the suffix of the
722-- | /O(n)/ drop n, applied to a stream, returns the suffix of the
723-- stream of length @n@, or the empty stream if @n@ is greater than the
723-- stream of length @n@, or the empty stream if @n@ is greater than the
724-- length of the stream.
724-- length of the stream.
@@ -768,7 +768,7 @@ dropWhile p (Stream next0 s0 len) = Stream next (S1 :!: s0) len
768{-# INLINE [0] dropWhile #-}
768{-# INLINE [0] dropWhile #-}
769
769
770-- ----------------------------------------------------------------------------
770-- ----------------------------------------------------------------------------
771−-- * Searching
771+-- * Searching
772
772
773-------------------------------------------------------------------------------
773-------------------------------------------------------------------------------
774-- ** Searching by equality
774-- ** Searching by equality
@@ -794,7 +794,7 @@ elem w (Stream next s0 len) = loop_elem s0
794find :: (Char -> Bool) -> Stream Char -> Maybe Char
794find :: (Char -> Bool) -> Stream Char -> Maybe Char
795find p (Stream next s0 len) = loop_find s0
795find p (Stream next s0 len) = loop_find s0
796 where
796 where
797− loop_find !s = case next s of
797+ loop_find !s = case next s of
798 Done -> Nothing
798 Done -> Nothing
799 Skip s' -> loop_find s'
799 Skip s' -> loop_find s'
800 Yield x s' | p x -> Just x
800 Yield x s' | p x -> Just x
@@ -851,7 +851,7 @@ findIndex p (Stream next s0 len) = loop_findIndex 0 s0
851
851
852-- | /O(n)/ The 'elemIndex' function returns the index of the first
852-- | /O(n)/ The 'elemIndex' function returns the index of the first
853-- element in the given stream which is equal to the query
853-- element in the given stream which is equal to the query
854−-- element, or 'Nothing' if there is no such element.
854+-- element, or 'Nothing' if there is no such element.
855elemIndex :: Char -> Stream Char -> Maybe Int
855elemIndex :: Char -> Stream Char -> Maybe Int
856elemIndex a (Stream next s0 len) = loop_elemIndex 0 s0
856elemIndex a (Stream next s0 len) = loop_elemIndex 0 s0
857 where
857 where
@@ -875,7 +875,7 @@ zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) = Stream next (sa0 :!:
875 Done -> Done
875 Done -> Done
876 Skip sa' -> Skip (sa' :!: sb :!: Nothing)
876 Skip sa' -> Skip (sa' :!: sb :!: Nothing)
877 Yield a sa' -> Skip (sa' :!: sb :!: Just a)
877 Yield a sa' -> Skip (sa' :!: sb :!: Just a)
878−
878+
879 next (sa' :!: sb :!: Just a) = case next1 sb of
879 next (sa' :!: sb :!: Just a) = case next1 sb of
880 Done -> Done
880 Done -> Done
881 Skip sb' -> Skip (sa' :!: sb' :!: Just a)
881 Skip sb' -> Skip (sa' :!: sb' :!: Just a)
@@ -884,4 +884,4 @@ zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) = Stream next (sa0 :!:
884
884
885errorEmptyList :: String -> a
885errorEmptyList :: String -> a
886errorEmptyList fun =
886errorEmptyList fun =
887− error ("Prelude." ++ fun ++ ": empty list")
887+ error ("Prelude." ++ fun ++ ": empty list")
Text/Internal.hs+3−3
@@ -4,8 +4,8 @@ import Data.Array.ST(newArray_,runSTUArray)
4import Data.Array.Unboxed(UArray(..))
4import Data.Array.Unboxed(UArray(..))
5import Data.Word(Word16(..))
5import Data.Word(Word16(..))
6
6
7−data Text = Text !(UArray Int Word16) {-# UNPACK #-}!Int {-# UNPACK #-}!Int
7+data Text = Text !(UArray Int Word16) {-# UNPACK #-}!Int {-# UNPACK #-}!Int
8
8
9empty :: Text
9empty :: Text
10−empty = Text (runSTUArray (newArray_ (0,0))) 0 0
10+empty = Text (runSTUArray (newArray_ (0,0))) 0 0
11−{-# INLINE [1] empty #-}
11+{-# INLINE [1] empty #-}
Text/Utf8.hs+11−11
@@ -9,7 +9,7 @@ import GHC.Exts
9import GHC.Prim
9import GHC.Prim
10import GHC.Word
10import GHC.Word
11
11
12−between :: Word8 -> Word8 -> Word8 -> Bool
12+between :: Word8 -> Word8 -> Word8 -> Bool
13between x y z = x >= y && x <= z
13between x y z = x >= y && x <= z
14{-# INLINE between #-}
14{-# INLINE between #-}
15
15
@@ -31,7 +31,7 @@ ord3 c = (x1,x2,x3)
31ord4 :: Char -> (Word8,Word8,Word8,Word8)
31ord4 :: Char -> (Word8,Word8,Word8,Word8)
32ord4 c = (x1,x2,x3,x4)
32ord4 c = (x1,x2,x3,x4)
33 where
33 where
34− n = ord c
34+ n = ord c
35 x1 = fromIntegral $ (shiftR n 18) + (0xF0::Int) :: Word8
35 x1 = fromIntegral $ (shiftR n 18) + (0xF0::Int) :: Word8
36 x2 = fromIntegral $ ((shiftR n 12) .&. (0x3F::Int)) + (0x80::Int) :: Word8
36 x2 = fromIntegral $ ((shiftR n 12) .&. (0x3F::Int)) + (0x80::Int) :: Word8
37 x3 = fromIntegral $ ((shiftR n 6) .&. (0x3F::Int)) + (0x80::Int) :: Word8
37 x3 = fromIntegral $ ((shiftR n 6) .&. (0x3F::Int)) + (0x80::Int) :: Word8
@@ -47,7 +47,7 @@ chr2 (W8# x1#) (W8# x2#) = C# (chr# (z1# +# z2#))
47{-# INLINE chr2 #-}
47{-# INLINE chr2 #-}
48
48
49chr3 :: Word8 -> Word8 -> Word8 -> Char
49chr3 :: Word8 -> Word8 -> Word8 -> Char
50−chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#))
50+chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#))
51 where
51 where
52 y1# = word2Int# x1#
52 y1# = word2Int# x1#
53 y2# = word2Int# x2#
53 y2# = word2Int# x2#
@@ -58,7 +58,7 @@ chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#))
58{-# INLINE chr3 #-}
58{-# INLINE chr3 #-}
59
59
60chr4 :: Word8 -> Word8 -> Word8 -> Word8 -> Char
60chr4 :: Word8 -> Word8 -> Word8 -> Word8 -> Char
61−chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) =
61+chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) =
62 C# (chr# (z1# +# z2# +# z3# +# z4#))
62 C# (chr# (z1# +# z2# +# z3# +# z4#))
63 where
63 where
64 y1# = word2Int# x1#
64 y1# = word2Int# x1#
@@ -94,15 +94,15 @@ validate4 x1 x2 x3 x4 = validate4_1 x1 x2 x3 x4 ||
94
94
95
95
96
96
97−validate3_1 x1 x2 x3 = (x1 == 0xE0) &&
97+validate3_1 x1 x2 x3 = (x1 == 0xE0) &&
98− between x2 0xA0 0xBF &&
98+ between x2 0xA0 0xBF &&
99 between x3 0x80 0xBF
99 between x3 0x80 0xBF
100{-# INLINE validate3_1 #-}
100{-# INLINE validate3_1 #-}
101
101
102validate3_2 x1 x2 x3 = between x1 0xE1 0xEC &&
102validate3_2 x1 x2 x3 = between x1 0xE1 0xEC &&
103 between x2 0x80 0xBF &&
103 between x2 0x80 0xBF &&
104 between x3 0x80 0xBF
104 between x3 0x80 0xBF
105−{-# INLINE validate3_2 #-}
105+{-# INLINE validate3_2 #-}
106
106
107validate3_3 x1 x2 x3 = x1 == 0xED &&
107validate3_3 x1 x2 x3 = x1 == 0xED &&
108 between x2 0x80 0x9F &&
108 between x2 0x80 0x9F &&
@@ -118,17 +118,17 @@ validate3_4 x1 x2 x3 = between x1 0xEE 0xEF &&
118validate4_1 x1 x2 x3 x4 = x1 == 0xF0 &&
118validate4_1 x1 x2 x3 x4 = x1 == 0xF0 &&
119 between x2 0x90 0xBF &&
119 between x2 0x90 0xBF &&
120 between x3 0x80 0xBF &&
120 between x3 0x80 0xBF &&
121− between x4 0x80 0xBF
121+ between x4 0x80 0xBF
122{-# INLINE validate4_1 #-}
122{-# INLINE validate4_1 #-}
123
123
124validate4_2 x1 x2 x3 x4 = between x1 0xF1 0xF3 &&
124validate4_2 x1 x2 x3 x4 = between x1 0xF1 0xF3 &&
125 between x2 0x80 0xBF &&
125 between x2 0x80 0xBF &&
126 between x3 0x80 0xBF &&
126 between x3 0x80 0xBF &&
127− between x4 0x80 0xBF
127+ between x4 0x80 0xBF
128{-# INLINE validate4_2 #-}
128{-# INLINE validate4_2 #-}
129
129
130validate4_3 x1 x2 x3 x4 = x1 == 0xF4 &&
130validate4_3 x1 x2 x3 x4 = x1 == 0xF4 &&
131 between x2 0x80 0x8F &&
131 between x2 0x80 0x8F &&
132 between x3 0x80 0xBF &&
132 between x3 0x80 0xBF &&
133− between x4 0x80 0xBF
133+ between x4 0x80 0xBF
134−{-# INLINE validate4_3 #-}
134+{-# INLINE validate4_3 #-}