🐙 Templated web page generator for your git repositories
git clone https://github.com/m-col/gitja
Files | Refs | Readme | License

Commit c24cb7b7b0bb10ccb57dc6aa74f6d47defff4992
Parent: ad3b01617373236314610f566029debc77f69aa1
Author: mcol <mcol@posteo.net>
Date: 2021-10-04 11:41:01 +0100
Committer: mcol <mcol@posteo.net>
Committed: 2021-10-04 11:41:02 +0100

Use Text.takeWhile and dropWhile to break commit logs

This have O(n) instead of the O(n+m) of breakOn.

src/Repositories.hs Modified

@@ -17,7 +17,7 @@
 import Data.Default (def)
 import Data.Either (fromRight)
 import Data.Tagged
-import Data.Text (pack, unpack, Text, strip, breakOn, replace, append)
+import Data.Text (pack, unpack, Text, strip, takeWhile, replace, append)
 import Data.Text.Encoding (decodeUtf8With)
 import Data.Text.Encoding.Error (lenientDecode)
 import Data.Maybe (mapMaybe)
@@ -31,6 +31,7 @@
 import Text.Ginger.Run (Run)
 import Text.Ginger.Parse (SourcePos)
 import qualified Data.HashMap.Strict as HashMap
+import qualified Data.Text as T
 
 import Config
 import Templates
@@ -152,8 +153,8 @@
 commitAsLookup :: Commit LgRepo -> Text -> Maybe (GVal m)
 commitAsLookup commit = \case
     "id" -> Just . toGVal . show . commitOid $ commit
-    "title" -> Just . toGVal . strip . fst . breakOn "\n" . commitLog $ commit
-    "body" -> Just . toGVal . strip . snd . breakOn "\n" . commitLog $ commit
+    "title" -> Just . toGVal . strip . T.takeWhile (/= '\n') . commitLog $ commit
+    "body" -> Just . toGVal . strip . T.dropWhile (/= '\n') . commitLog $ commit
     "message" -> Just . toGVal . strip . commitLog $ commit
     "author" -> Just . toGVal . strip . signatureName . commitAuthor $ commit
     "committer" -> Just . toGVal . strip . signatureName . commitCommitter $ commit