one more attempt to fix no-readback cache algorithm
This commit is contained in:
parent
b3d2877274
commit
b078f908f0
|
@ -431,36 +431,33 @@ namespace libtorrent
|
||||||
int current = 0;
|
int current = 0;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int blocks_in_piece = 0;
|
int blocks_in_piece = (p.storage->info()->piece_size(p.piece)
|
||||||
int first_block = -1;
|
+ m_block_size - 1) / m_block_size;
|
||||||
|
|
||||||
if (avoid_readback)
|
if (avoid_readback)
|
||||||
{
|
{
|
||||||
// with the avoid read-back mode, only consider blocks
|
start = p.next_block_to_hash;
|
||||||
// below the next_block_to_hash cursor
|
for (int i = p.next_block_to_hash; i < blocks_in_piece; ++i)
|
||||||
blocks_in_piece = p.next_block_to_hash;
|
{
|
||||||
|
if (p.blocks[i].buf) ++current;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
blocks_in_piece = (p.storage->info()->piece_size(p.piece)
|
for (int i = 0; i < blocks_in_piece; ++i)
|
||||||
+ m_block_size - 1) / m_block_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < blocks_in_piece; ++i)
|
|
||||||
{
|
|
||||||
if (p.blocks[i].buf)
|
|
||||||
{
|
{
|
||||||
if (first_block == -1) first_block = i;
|
if (p.blocks[i].buf) ++current;
|
||||||
++current;
|
else
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (current > len)
|
|
||||||
{
|
{
|
||||||
len = current;
|
if (current > len)
|
||||||
pos = start;
|
{
|
||||||
|
len = current;
|
||||||
|
pos = start;
|
||||||
|
}
|
||||||
|
current = 0;
|
||||||
|
start = i + 1;
|
||||||
}
|
}
|
||||||
current = 0;
|
|
||||||
start = i + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (current > len)
|
if (current > len)
|
||||||
|
@ -469,12 +466,6 @@ namespace libtorrent
|
||||||
pos = start;
|
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;
|
if (len < lower_limit || len <= 0) return 0;
|
||||||
len = flush_range(p, pos, pos + len, l);
|
len = flush_range(p, pos, pos + len, l);
|
||||||
return len;
|
return len;
|
||||||
|
|
Loading…
Reference in New Issue