one more attempt to fix no-readback cache algorithm

This commit is contained in:
Arvid Norberg 2011-09-27 10:46:56 +00:00
parent b3d2877274
commit b078f908f0
1 changed files with 19 additions and 28 deletions

View File

@ -431,36 +431,33 @@ namespace libtorrent
int current = 0;
int pos = 0;
int start = 0;
int blocks_in_piece = 0;
int first_block = -1;
int blocks_in_piece = (p.storage->info()->piece_size(p.piece)
+ m_block_size - 1) / m_block_size;
if (avoid_readback)
{
// with the avoid read-back mode, only consider blocks
// below the next_block_to_hash cursor
blocks_in_piece = p.next_block_to_hash;
start = p.next_block_to_hash;
for (int i = p.next_block_to_hash; i < blocks_in_piece; ++i)
{
if (p.blocks[i].buf) ++current;
else break;
}
}
else
{
blocks_in_piece = (p.storage->info()->piece_size(p.piece)
+ m_block_size - 1) / m_block_size;
}
for (int i = 0; i < blocks_in_piece; ++i)
{
if (p.blocks[i].buf)
for (int i = 0; i < blocks_in_piece; ++i)
{
if (first_block == -1) first_block = i;
++current;
}
else
{
if (current > len)
if (p.blocks[i].buf) ++current;
else
{
len = current;
pos = start;
if (current > len)
{
len = current;
pos = start;
}
current = 0;
start = i + 1;
}
current = 0;
start = i + 1;
}
}
if (current > len)
@ -469,12 +466,6 @@ namespace libtorrent
pos = start;
}
if (avoid_readback && first_block >= 0 && p.next_block_to_hash - first_block > lower_limit)
{
len = flush_range(p, first_block, p.next_block_to_hash, l);
return len;
}
if (len < lower_limit || len <= 0) return 0;
len = flush_range(p, pos, pos + len, l);
return len;