on master help sign in
Merge Nicolas's changes in
6a587fdBryan O'Sullivan
Data/Text/Fusion.hs−49
@@ -121,55 +121,6 @@ length :: Stream Char -> Int
121length = S.lengthI
121length = S.lengthI
122{-# INLINE[0] length #-}
122{-# INLINE[0] length #-}
123
123
124−-- | /O(n)/ Returns the number of characters in a text.
125−length64 :: Stream Char -> Int64
126−length64 (Stream next s0 _len) = loop_length 0 s0
127− where
128− loop_length z s = case next s of
129− Done -> z
130− Skip s' -> loop_length z s'
131− Yield _ s' -> let !z' = z + 1
132− in loop_length z' s'
133−{-# INLINE[0] length64 #-}
134−
135−-- ----------------------------------------------------------------------------
136−-- * Stream transformations
137−
138−-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
139−-- @xs@.
140−map :: (Char -> Char) -> Stream Char -> Stream Char
141−map f (Stream next0 s0 len) = Stream next s0 len
142− where
143− {-# INLINE next #-}
144− next !s = case next0 s of
145− Done -> Done
146− Skip s' -> Skip s'
147− Yield x s' -> Yield (f x) s'
148−{-# INLINE [0] map #-}
149−
150−{-#
151− RULES "STREAM map/map fusion" forall f g s.
152− map f (map g s) = map (\x -> f (g x)) s
153− #-}
154−
155−-- | /O(n)/ Take a character and place it between each of the
156−-- characters of a 'Stream Char'.
157−intersperse :: Char -> Stream Char -> Stream Char
158−intersperse c (Stream next0 s0 len) = Stream next (s0 :!: Nothing :!: S1) len
159− where
160− {-# INLINE next #-}
161− next (s :!: Nothing :!: S1) = case next0 s of
162− Done -> Done
163− Skip s' -> Skip (s' :!: Nothing :!: S1)
164− Yield x s' -> Skip (s' :!: Just x :!: S1)
165− next (s :!: Just x :!: S1) = Yield x (s :!: Nothing :!: S2)
166− next (s :!: Nothing :!: S2) = case next0 s of
167− Done -> Done
168− Skip s' -> Skip (s' :!: Nothing :!: S2)
169− Yield x s' -> Yield c (s' :!: Just x :!: S1)
170− next _ = internalError "intersperse"
171−{-# INLINE [0] intersperse #-}
172−
173-- | /O(n)/ Reverse the characters of a string.
124-- | /O(n)/ Reverse the characters of a string.
174reverse :: Stream Char -> Text
125reverse :: Stream Char -> Text
175reverse (Stream next s len0)
126reverse (Stream next s len0)
Data/Text/Fusion/Common.hs+2−3
@@ -240,11 +240,10 @@ null (Stream next s0 _len) = loop_null s0
240lengthI :: Integral a => Stream Char -> a
240lengthI :: Integral a => Stream Char -> a
241lengthI (Stream next s0 _len) = loop_length 0 s0
241lengthI (Stream next s0 _len) = loop_length 0 s0
242 where
242 where
243− loop_length z s = case next s of
243+ loop_length !z s = case next s of
244 Done -> z
244 Done -> z
245 Skip s' -> loop_length z s'
245 Skip s' -> loop_length z s'
246− Yield _ s' -> let !z' = z + 1
246+ Yield _ s' -> loop_length (z + 1) s'
247− in loop_length z' s'
248{-# INLINE[0] lengthI #-}
247{-# INLINE[0] lengthI #-}
249
248
250-- ----------------------------------------------------------------------------
249-- ----------------------------------------------------------------------------
Data/Text/Lazy.hs+2−2
@@ -592,8 +592,8 @@ splitAt = loop
592 where loop _ Empty = (empty, empty)
592 where loop _ Empty = (empty, empty)
593 loop n t | n <= 0 = (empty, t)
593 loop n t | n <= 0 = (empty, t)
594 loop n (Chunk t ts)
594 loop n (Chunk t ts)
595− | n < len = let (ts',ts'') = T.splitAt n t
595+ | n < len = let (t',t'') = T.splitAt (fromIntegral n) t
596− in (Chunk ts' Empty, Chunk ts'' Empty)
596+ in (Chunk t' Empty, Chunk t'' ts)
597 | otherwise = let (ts',ts'') = loop (n - len) ts
597 | otherwise = let (ts',ts'') = loop (n - len) ts
598 in (Chunk t ts', ts'')
598 in (Chunk t ts', ts'')
599 where len = fromIntegral (T.length t)
599 where len = fromIntegral (T.length t)