2008-01-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Added Piece::getFirstMissingBlockIndexWithoutLock() and it is 
called
	from PiecedSegment's ctor.
	Previously Piece::getAllMissingBlockIndexes() is called from
	PiecedSegment() but it is rather expensive since only first 
element is
	used.
	* src/PiecedSegment.cc
	* src/Piece.{h, cc}
pull/1/head
Tatsuhiro Tsujikawa 2008-01-11 13:37:46 +00:00
parent 5516bc02cb
commit 1a4100cbc9
4 changed files with 17 additions and 1 deletions

View File

@ -1,3 +1,13 @@
2008-01-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added Piece::getFirstMissingBlockIndexWithoutLock() and it is called
from PiecedSegment's ctor.
Previously Piece::getAllMissingBlockIndexes() is called from
PiecedSegment() but it is rather expensive since only first element is
used.
* src/PiecedSegment.cc
* src/Piece.{h, cc}
2008-01-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten get*Missing*Index functions. Now no need to allocate memory

View File

@ -95,6 +95,11 @@ int32_t Piece::getMissingBlockIndex() const {
return blockIndex;
}
int32_t Piece::getFirstMissingBlockIndexWithoutLock() const
{
return bitfield->getFirstMissingIndex();
}
BlockIndexes Piece::getAllMissingBlockIndexes() const {
return bitfield->getAllMissingIndexes();
}

View File

@ -86,6 +86,7 @@ public:
int32_t getMissingUnusedBlockIndex() const;
int32_t getMissingBlockIndex() const;
int32_t getFirstMissingBlockIndexWithoutLock() const;
BlockIndexes getAllMissingBlockIndexes() const;
void completeBlock(int32_t blockIndex);
void cancelBlock(int32_t blockIndex);

View File

@ -38,7 +38,7 @@
PiecedSegment::PiecedSegment(int32_t pieceLength, const PieceHandle& piece):
_pieceLength(pieceLength), _overflowLength(0), _piece(piece)
{
_writtenLength = _piece->getAllMissingBlockIndexes().front()*_piece->getBlockLength();
_writtenLength = _piece->getFirstMissingBlockIndexWithoutLock()*_piece->getBlockLength();
}
PiecedSegment::~PiecedSegment() {}