2009-08-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Avoided unnecessary memory allocation in
	BitfieldMan::getCompletedLength().
	* src/BitfieldMan.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-08-18 14:21:02 +00:00
parent a4d5134f80
commit c1f4af537a
2 changed files with 12 additions and 3 deletions

View File

@ -1,3 +1,9 @@
2009-08-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Avoided unnecessary memory allocation in
BitfieldMan::getCompletedLength().
* src/BitfieldMan.cc
2009-08-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that download fails if

View File

@ -675,8 +675,9 @@ uint64_t BitfieldMan::getFilteredTotalLengthNow() const {
}
uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
unsigned char* temp = new unsigned char[bitfieldLength];
unsigned char* temp;
if(useFilter) {
temp = new unsigned char[bitfieldLength];
for(size_t i = 0; i < bitfieldLength; ++i) {
temp[i] = bitfield[i];
if(filterEnabled) {
@ -684,7 +685,7 @@ uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
}
}
} else {
memcpy(temp, bitfield, bitfieldLength);
temp = bitfield;
}
size_t completedBlocks = bitfield::countSetBit(temp, blocks);
uint64_t completedLength = 0;
@ -697,7 +698,9 @@ uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
completedLength = ((uint64_t)completedBlocks)*blockLength;
}
}
delete [] temp;
if(useFilter) {
delete [] temp;
}
return completedLength;
}