summaryrefslogtreecommitdiff
path: root/src/System/Torrent
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-06 00:09:58 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-06 00:09:58 +0400
commita95d2aab3f8b11b681cd19c89322e485150dc647 (patch)
treec3a88a2a25f7ade8130b4861d75b4202bd2fd54c /src/System/Torrent
parenta467181b6aa21b1e41d56e7772d481cbf0c37f39 (diff)
Avoid piece copying in verifyPiece
Diffstat (limited to 'src/System/Torrent')
-rw-r--r--src/System/Torrent/Storage.hs6
1 files changed, 5 insertions, 1 deletions
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 {..}
135hintRead :: PieceIx -> Storage -> IO () 135hintRead :: PieceIx -> Storage -> IO ()
136hintRead _pix Storage {..} = return () 136hintRead _pix Storage {..} = return ()
137 137
138-- | Zero-copy version of readPiece. Can be used only with 'ReadOnly'
139-- storages.
138unsafeReadPiece :: PieceIx -> Storage -> IO (Piece BL.ByteString) 140unsafeReadPiece :: PieceIx -> Storage -> IO (Piece BL.ByteString)
139unsafeReadPiece pix s @ Storage {..} 141unsafeReadPiece pix s @ Storage {..}
140 | not (isValidIx pix s) = throwIO (InvalidIndex pix) 142 | not (isValidIx pix s) = throwIO (InvalidIndex pix)
@@ -170,7 +172,9 @@ genPieceInfo s = do
170 172
171-- | Verify specific piece using infodict hash list. 173-- | Verify specific piece using infodict hash list.
172verifyPiece :: Storage -> PieceInfo -> PieceIx -> IO Bool 174verifyPiece :: Storage -> PieceInfo -> PieceIx -> IO Bool
173verifyPiece s pinfo pix = checkPieceLazy pinfo <$> readPiece pix s 175verifyPiece s pinfo pix = do
176 piece <- unsafeReadPiece pix s
177 return $! checkPieceLazy pinfo piece
174 178
175-- | Verify storage. 179-- | Verify storage.
176-- 180--