tibbe avatar tibbe committed 6249e01

Optimize scan

Comments (0)

Files changed (1)


 import Foreign.Ptr (castPtr, minusPtr, plusPtr)
 import Foreign.Storable (Storable(peek, sizeOf))
 import Prelude hiding (getChar, take, takeWhile)
-import System.IO.Unsafe (unsafePerformIO)
+import System.IO.Unsafe (unsafeDupablePerformIO)
 import qualified Data.Attoparsec.Internal.Types as T
 import qualified Data.ByteString as B8
 import qualified Data.ByteString.Char8 as B
   chunks <- go [] s0
   case chunks of
     [x] -> return x
-    xs  -> return . B.concat . reverse $ xs
+    xs  -> return $! B.concat $ reverse xs
   go acc s1 = do
     let scanner (B.PS fp off len) =
                 done !i !s = return (T i s)
             inner start s1
     bs <- get
-    let T i s' = unsafePerformIO $ scanner bs
-        h = B.unsafeTake i bs
-        t = B.unsafeDrop i bs
+    let T i s' = unsafeDupablePerformIO $ scanner bs
+        !h = B.unsafeTake i bs
+        !t = B.unsafeDrop i bs
     put t
     if B.null t
       then do
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.