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
pull/1/head
Tatsuhiro Tsujikawa 2009-03-20 13:35:40 +00:00
parent ef927009b7
commit 3644682511
2 changed files with 23 additions and 12 deletions

View File

@ -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>
Cached TransferStat/download speed to avoid to sum them up in each

View File

@ -212,8 +212,10 @@ bool BitfieldMan::getMissingIndexRandomly(size_t& index,
} else {
mask = 0xff;
}
if(bitfield[byte]&mask) {
index = byte*8+getNthBitIndex(bitfield[byte], 1);
unsigned char bits = bitfield[byte];
if(bits&mask) {
index = byte*8+getNthBitIndex(bits, 1);
return true;
}
byte++;
@ -270,11 +272,12 @@ template<typename Array>
bool BitfieldMan::getFirstMissingIndex(size_t& index, const Array& bitfield, size_t bitfieldLength) const
{
for(size_t i = 0; i < bitfieldLength; ++i) {
size_t base = i*8;
for(size_t bi = 0; bi < 8 && base+bi < blocks; ++bi) {
unsigned char mask = 128 >> bi;
if(bitfield[i] & mask) {
index = base+bi;
unsigned char bits = bitfield[i];
unsigned char mask = 128;
size_t tindex = i*8;
for(size_t bi = 0; bi < 8 && tindex < blocks; ++bi, mask >>= 1, ++tindex) {
if(bits & mask) {
index = tindex;
return true;
}
}
@ -395,11 +398,12 @@ bool BitfieldMan::getAllMissingIndexes(std::deque<size_t>& indexes,
size_t bitfieldLength) const
{
for(size_t i = 0; i < bitfieldLength; ++i) {
size_t base = i*8;
for(size_t bi = 0; bi < 8 && base+bi < blocks; ++bi) {
unsigned char mask = 128 >> bi;
if(bitfield[i] & mask) {
indexes.push_back(base+bi);
unsigned char bits = bitfield[i];
unsigned char mask = 128;
size_t index = i*8;
for(size_t bi = 0; bi < 8 && index < blocks; ++bi, mask >>= 1, ++index) {
if(bits & mask) {
indexes.push_back(index);
}
}
}