on master help sign in
Speed up init.
187893fBryan O'Sullivan
Data/Text/Fusion/Common.hs+9−7
@@ -228,20 +228,22 @@ tail (Stream next0 s0 len) = Stream next (C0 s0) (len-1)
228 Yield x s' -> Yield x (C1 s')
228 Yield x s' -> Yield x (C1 s')
229{-# INLINE [0] tail #-}
229{-# INLINE [0] tail #-}
230
230
231+data Init s = Init0 !s
232+ | Init1 {-# UNPACK #-} !Char !s
231
233
232-- | /O(1)/ Returns all but the last character of a Stream Char, which
234-- | /O(1)/ Returns all but the last character of a Stream Char, which
233-- must be non-empty.
235-- must be non-empty.
234init :: Stream Char -> Stream Char
236init :: Stream Char -> Stream Char
235−init (Stream next0 s0 len) = Stream next (N :*: s0) (len-1)
237+init (Stream next0 s0 len) = Stream next (Init0 s0) (len-1)
236 where
238 where
237− next (N :*: s) = case next0 s of
239+ next (Init0 s) = case next0 s of
238 Done -> emptyError "init"
240 Done -> emptyError "init"
239− Skip s' -> Skip (N :*: s')
241+ Skip s' -> Skip (Init0 s')
240− Yield x s' -> Skip (J x :*: s')
242+ Yield x s' -> Skip (Init1 x s')
241− next (J x :*: s) = case next0 s of
243+ next (Init1 x s) = case next0 s of
242 Done -> Done
244 Done -> Done
243− Skip s' -> Skip (J x :*: s')
245+ Skip s' -> Skip (Init1 x s')
244− Yield x' s' -> Yield x (J x' :*: s')
246+ Yield x' s' -> Yield x (Init1 x' s')
245{-# INLINE [0] init #-}
247{-# INLINE [0] init #-}
246
248
247-- | /O(1)/ Tests whether a Stream Char is empty or not.
249-- | /O(1)/ Tests whether a Stream Char is empty or not.