Bryan O'Sullivan avatar Bryan O'Sullivan committed a634bc2

Speed up init.

Comments (0)

Files changed (1)

Data/Text/Fusion/Common.hs

                       Yield x s' -> Yield x (C1 s')
 {-# INLINE [0] tail #-}
 
+data Init s = Init0 !s
+            | Init1 {-# UNPACK #-} !Char !s
 
 -- | /O(1)/ Returns all but the last character of a Stream Char, which
 -- must be non-empty.
 init :: Stream Char -> Stream Char
-init (Stream next0 s0 len) = Stream next (N :*: s0) (len-1)
+init (Stream next0 s0 len) = Stream next (Init0 s0) (len-1)
     where
-      next (N :*: s) = case next0 s of
+      next (Init0 s) = case next0 s of
                          Done       -> emptyError "init"
-                         Skip s'    -> Skip (N :*: s')
-                         Yield x s' -> Skip (J x  :*: s')
-      next (J x :*: s)  = case next0 s of
+                         Skip s'    -> Skip (Init0 s')
+                         Yield x s' -> Skip (Init1 x s')
+      next (Init1 x s)  = case next0 s of
                             Done        -> Done
-                            Skip s'     -> Skip    (J x  :*: s')
-                            Yield x' s' -> Yield x (J x' :*: s')
+                            Skip s'     -> Skip    (Init1 x s')
+                            Yield x' s' -> Yield x (Init1 x' s')
 {-# INLINE [0] init #-}
 
 -- | /O(1)/ Tests whether a Stream Char is empty or not.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.