mirror of https://github.com/aria2/aria2
2009-08-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Avoided unnecessary memory allocation in BitfieldMan::getCompletedLength(). * src/BitfieldMan.ccpull/1/head
parent
a4d5134f80
commit
c1f4af537a
|
@ -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>
|
2009-08-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Fixed the bug that download fails if
|
Fixed the bug that download fails if
|
||||||
|
|
|
@ -675,8 +675,9 @@ uint64_t BitfieldMan::getFilteredTotalLengthNow() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
|
uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
|
||||||
unsigned char* temp = new unsigned char[bitfieldLength];
|
unsigned char* temp;
|
||||||
if(useFilter) {
|
if(useFilter) {
|
||||||
|
temp = new unsigned char[bitfieldLength];
|
||||||
for(size_t i = 0; i < bitfieldLength; ++i) {
|
for(size_t i = 0; i < bitfieldLength; ++i) {
|
||||||
temp[i] = bitfield[i];
|
temp[i] = bitfield[i];
|
||||||
if(filterEnabled) {
|
if(filterEnabled) {
|
||||||
|
@ -684,7 +685,7 @@ uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
memcpy(temp, bitfield, bitfieldLength);
|
temp = bitfield;
|
||||||
}
|
}
|
||||||
size_t completedBlocks = bitfield::countSetBit(temp, blocks);
|
size_t completedBlocks = bitfield::countSetBit(temp, blocks);
|
||||||
uint64_t completedLength = 0;
|
uint64_t completedLength = 0;
|
||||||
|
@ -697,7 +698,9 @@ uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
|
||||||
completedLength = ((uint64_t)completedBlocks)*blockLength;
|
completedLength = ((uint64_t)completedBlocks)*blockLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete [] temp;
|
if(useFilter) {
|
||||||
|
delete [] temp;
|
||||||
|
}
|
||||||
return completedLength;
|
return completedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue