diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-06 00:09:58 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-06 00:09:58 +0400 |
commit | a95d2aab3f8b11b681cd19c89322e485150dc647 (patch) | |
tree | c3a88a2a25f7ade8130b4861d75b4202bd2fd54c /src/System/Torrent | |
parent | a467181b6aa21b1e41d56e7772d481cbf0c37f39 (diff) |
Avoid piece copying in verifyPiece
Diffstat (limited to 'src/System/Torrent')
-rw-r--r-- | src/System/Torrent/Storage.hs | 6 |
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 {..} | |||
135 | hintRead :: PieceIx -> Storage -> IO () | 135 | hintRead :: PieceIx -> Storage -> IO () |
136 | hintRead _pix Storage {..} = return () | 136 | hintRead _pix Storage {..} = return () |
137 | 137 | ||
138 | -- | Zero-copy version of readPiece. Can be used only with 'ReadOnly' | ||
139 | -- storages. | ||
138 | unsafeReadPiece :: PieceIx -> Storage -> IO (Piece BL.ByteString) | 140 | unsafeReadPiece :: PieceIx -> Storage -> IO (Piece BL.ByteString) |
139 | unsafeReadPiece pix s @ Storage {..} | 141 | unsafeReadPiece 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. |
172 | verifyPiece :: Storage -> PieceInfo -> PieceIx -> IO Bool | 174 | verifyPiece :: Storage -> PieceInfo -> PieceIx -> IO Bool |
173 | verifyPiece s pinfo pix = checkPieceLazy pinfo <$> readPiece pix s | 175 | verifyPiece s pinfo pix = do |
176 | piece <- unsafeReadPiece pix s | ||
177 | return $! checkPieceLazy pinfo piece | ||
174 | 178 | ||
175 | -- | Verify storage. | 179 | -- | Verify storage. |
176 | -- | 180 | -- |