From b089fba7b4e68c4482909319f562d32a3f00f379 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 29 Jun 2011 23:56:47 -0400 Subject: use ByteString for hGet Avoids the crazy low-level hGetBuf stuff. Also slightly faster. --- Branch.hs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/Branch.hs b/Branch.hs index 033b7c6d0..9cdb096fd 100644 --- a/Branch.hs +++ b/Branch.hs @@ -26,9 +26,7 @@ import System.Cmd.Utils import Data.Maybe import Data.List import System.IO -import System.IO.Unsafe -import Foreign -import Data.Char +import qualified Data.ByteString.Char8 as B import Types.BranchState import qualified GitRepo as Git @@ -258,23 +256,11 @@ catFile file = do else do let [_sha, _type, size] = words header let bytes = read size - fp <- mallocForeignPtrBytes (fromIntegral bytes) - len <- withForeignPtr fp $ \buf -> hGetBuf from buf (fromIntegral bytes) - when (len /= bytes) $ - error "short read from git cat-file" - content <- lazySlurp fp 0 len + content <- B.hGet from bytes c <- hGetChar from when (c /= '\n') $ error "missing newline from git cat-file" - return content - -lazySlurp :: ForeignPtr Word8 -> Int -> Int -> IO String -lazySlurp fp ix len - | ix == len = return [] - | otherwise = do - c <- withForeignPtr fp $ \p -> peekElemOff p ix - cs <- unsafeInterleaveIO (lazySlurp fp (ix+1) len) - return $ chr (fromIntegral c) : cs + return $ B.unpack content {- Lists all files on the branch. There may be duplicates in the list. -} files :: Annex [FilePath] -- cgit v1.2.3