Skip to content

Commit

Permalink
Only hash the buffer if the read was successful. Should improve perfo…
Browse files Browse the repository at this point in the history
…rmance slightly for cases where the data does not exist.

svn path=/trunk/bitsharp/; revision=156065
  • Loading branch information
alanmcgovern committed Apr 25, 2010
1 parent 47d2872 commit 346ae16
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/MonoTorrent/MonoTorrent.Client/Managers/DiskManager.cs
Expand Up @@ -346,13 +346,18 @@ internal void BeginGetHash(TorrentManager manager, int pieceIndex, MainLoopResul
DiskIOCallback readCallback = null;
readCallback = delegate(bool successful) {

hasher.TransformBlock(hashBuffer, 0, count, hashBuffer, 0);
if (successful)
hasher.TransformBlock(hashBuffer, 0, count, hashBuffer, 0);
offset += count;

if (!successful || offset == endOffset)
{
hasher.TransformFinalBlock(hashBuffer, 0, 0);
object hash = successful ? hasher.Hash : null;
object hash = null;
if (successful)
{
hasher.TransformFinalBlock(hashBuffer, 0, 0);
hash = hasher.Hash;
}
((IDisposable)hasher).Dispose();
ClientEngine.BufferManager.FreeBuffer(ref hashBuffer);
ClientEngine.MainLoop.Queue(delegate {
Expand Down

0 comments on commit 346ae16

Please sign in to comment.