From a95d2aab3f8b11b681cd19c89322e485150dc647 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Mon, 6 Jan 2014 00:09:58 +0400 Subject: Avoid piece copying in verifyPiece --- src/System/Torrent/Storage.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/System/Torrent/Storage.hs b/src/System/Torrent/Storage.hs index b5092b2e..8c220721 100644 --- a/src/System/Torrent/Storage.hs +++ b/src/System/Torrent/Storage.hs @@ -135,6 +135,8 @@ readPiece pix s @ Storage {..} hintRead :: PieceIx -> Storage -> IO () hintRead _pix Storage {..} = return () +-- | Zero-copy version of readPiece. Can be used only with 'ReadOnly' +-- storages. unsafeReadPiece :: PieceIx -> Storage -> IO (Piece BL.ByteString) unsafeReadPiece pix s @ Storage {..} | not (isValidIx pix s) = throwIO (InvalidIndex pix) @@ -170,7 +172,9 @@ genPieceInfo s = do -- | Verify specific piece using infodict hash list. verifyPiece :: Storage -> PieceInfo -> PieceIx -> IO Bool -verifyPiece s pinfo pix = checkPieceLazy pinfo <$> readPiece pix s +verifyPiece s pinfo pix = do + piece <- unsafeReadPiece pix s + return $! checkPieceLazy pinfo piece -- | Verify storage. -- -- cgit v1.2.3