convert formatLsTree to ByteString for speed
authorJoey Hess <joeyh@joeyh.name>
Mon, 17 May 2021 14:46:24 +0000 (10:46 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 17 May 2021 14:46:24 +0000 (10:46 -0400)
Git/LsTree.hs
Logs/Export.hs

index 2c57521c4508166fc36d6f3b872772afa3e8dadf..a49c4eaa789012a14290f5c1b9653f1aad7ec1c7 100644 (file)
@@ -28,6 +28,7 @@ import Utility.Attoparsec
 
 import Numeric
 import Data.Either
+import Data.Char
 import System.Posix.Types
 import qualified Data.ByteString as S
 import qualified Data.ByteString.Lazy as L
@@ -146,9 +147,9 @@ parserLsTree long = case long of
 
 {- Inverse of parseLsTree. Note that the long output format is not
  - generated, so any size information is not included. -}
-formatLsTree :: TreeItem -> String
-formatLsTree ti = unwords
-       [ showOct (mode ti) ""
-       , decodeBS (typeobj ti)
-       , fromRef (sha ti)
-       ] ++ ('\t' : fromRawFilePath (getTopFilePath (file ti)))
+formatLsTree :: TreeItem -> S.ByteString
+formatLsTree ti = S.intercalate (S.singleton (fromIntegral (ord ' ')))
+       [ encodeBS' (showOct (mode ti) "")
+       , typeobj ti
+       , fromRef' (sha ti)
+       ] <> (S.cons (fromIntegral (ord '\t')) (getTopFilePath (file ti)))
index 6fea1b9a9678b878cde7594755bfc9637009a828..ecbf4b4aa01409f96a4e69bd4b9d36bcd63594c4 100644 (file)
@@ -23,6 +23,7 @@ module Logs.Export (
 ) where
 
 import qualified Data.Map as M
+import qualified Data.ByteString as B
 
 import Annex.Common
 import qualified Annex.Branch
@@ -119,10 +120,10 @@ logExportExcluded :: UUID -> ((Git.Tree.TreeItem -> IO ()) -> Annex a) -> Annex
 logExportExcluded u a = do
        logf <- fromRepo $ gitAnnexExportExcludeLog u
        withLogHandle logf $ \logh -> do
-               liftIO $ hSetNewlineMode logh noNewlineTranslation
                a (writer logh)
   where
-       writer logh = hPutStrLn logh
+       writer logh = B.hPutStr logh
+               . flip B.snoc (fromIntegral (ord '\n'))
                . Git.LsTree.formatLsTree
                . Git.Tree.treeItemToLsTreeItem