Improve space efficiency of readDiff
Mon Jan 19 19:19:19 CET 2009 Joachim Breitner <mail@joachim-breitner.de>
* Improve space efficiency of readDiff
diff -rN -u old-darcswatch/src/Darcs.hs new-darcswatch/src/Darcs.hs
--- old-darcswatch/src/Darcs.hs 2014-11-29 10:30:53.261052482 +0100
+++ new-darcswatch/src/Darcs.hs 2014-11-29 10:30:54.165035780 +0100
@@ -34,6 +34,7 @@
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Char8 (ByteString)
+import Data.List
-- | The defining informtion of a Darcs patch.
data PatchInfo = PatchInfo
@@ -260,8 +261,8 @@
readDiff :: ByteString -> Maybe (ByteString, ByteString)
readDiff s | B.null (dropWhite s) = Nothing
-readDiff s = if null r then Nothing else Just (B.unlines p,B.unlines r)
- where (p,r) = break (\l -> B.null l || B.head l == '[') (B.lines s)
+readDiff s = find (\(p,r) -> B.pack "\n\n" `B.isPrefixOf` r || B.pack "\n[" `B.isPrefixOf` r)
+ (zip (B.inits s) (B.tails s))
patchFilename :: PatchInfo -> String
patchFilename pi = patchBasename pi ++ ".gz"