mirror of https://github.com/aria2/aria2
2009-03-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Refactored getMissingIndexRandomly, getFirstMissingIndex, getAllMissingBlockIndexes to reduce a call to array_function_base::operator[]. * src/BitfieldMan.ccpull/1/head
parent
ef927009b7
commit
3644682511
|
@ -1,3 +1,10 @@
|
||||||
|
2009-03-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Refactored getMissingIndexRandomly, getFirstMissingIndex,
|
||||||
|
getAllMissingBlockIndexes to reduce a call to
|
||||||
|
array_function_base::operator[].
|
||||||
|
* src/BitfieldMan.cc
|
||||||
|
|
||||||
2009-03-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-03-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Cached TransferStat/download speed to avoid to sum them up in each
|
Cached TransferStat/download speed to avoid to sum them up in each
|
||||||
|
|
|
@ -212,8 +212,10 @@ bool BitfieldMan::getMissingIndexRandomly(size_t& index,
|
||||||
} else {
|
} else {
|
||||||
mask = 0xff;
|
mask = 0xff;
|
||||||
}
|
}
|
||||||
if(bitfield[byte]&mask) {
|
unsigned char bits = bitfield[byte];
|
||||||
index = byte*8+getNthBitIndex(bitfield[byte], 1);
|
|
||||||
|
if(bits&mask) {
|
||||||
|
index = byte*8+getNthBitIndex(bits, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
byte++;
|
byte++;
|
||||||
|
@ -270,11 +272,12 @@ template<typename Array>
|
||||||
bool BitfieldMan::getFirstMissingIndex(size_t& index, const Array& bitfield, size_t bitfieldLength) const
|
bool BitfieldMan::getFirstMissingIndex(size_t& index, const Array& bitfield, size_t bitfieldLength) const
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < bitfieldLength; ++i) {
|
for(size_t i = 0; i < bitfieldLength; ++i) {
|
||||||
size_t base = i*8;
|
unsigned char bits = bitfield[i];
|
||||||
for(size_t bi = 0; bi < 8 && base+bi < blocks; ++bi) {
|
unsigned char mask = 128;
|
||||||
unsigned char mask = 128 >> bi;
|
size_t tindex = i*8;
|
||||||
if(bitfield[i] & mask) {
|
for(size_t bi = 0; bi < 8 && tindex < blocks; ++bi, mask >>= 1, ++tindex) {
|
||||||
index = base+bi;
|
if(bits & mask) {
|
||||||
|
index = tindex;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,11 +398,12 @@ bool BitfieldMan::getAllMissingIndexes(std::deque<size_t>& indexes,
|
||||||
size_t bitfieldLength) const
|
size_t bitfieldLength) const
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < bitfieldLength; ++i) {
|
for(size_t i = 0; i < bitfieldLength; ++i) {
|
||||||
size_t base = i*8;
|
unsigned char bits = bitfield[i];
|
||||||
for(size_t bi = 0; bi < 8 && base+bi < blocks; ++bi) {
|
unsigned char mask = 128;
|
||||||
unsigned char mask = 128 >> bi;
|
size_t index = i*8;
|
||||||
if(bitfield[i] & mask) {
|
for(size_t bi = 0; bi < 8 && index < blocks; ++bi, mask >>= 1, ++index) {
|
||||||
indexes.push_back(base+bi);
|
if(bits & mask) {
|
||||||
|
indexes.push_back(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue