From 1a4100cbc9c44ebc49cd76c989a5c5b188ea9ede Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 11 Jan 2008 13:37:46 +0000 Subject: [PATCH] 2008-01-11 Tatsuhiro Tsujikawa 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} --- ChangeLog | 10 ++++++++++ src/Piece.cc | 5 +++++ src/Piece.h | 1 + src/PiecedSegment.cc | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 31526336..ac62e58a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-01-11 Tatsuhiro Tsujikawa + + 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 Rewritten get*Missing*Index functions. Now no need to allocate memory diff --git a/src/Piece.cc b/src/Piece.cc index 4ed9fab7..ed866760 100644 --- a/src/Piece.cc +++ b/src/Piece.cc @@ -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(); } diff --git a/src/Piece.h b/src/Piece.h index d1428709..5686dab4 100644 --- a/src/Piece.h +++ b/src/Piece.h @@ -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); diff --git a/src/PiecedSegment.cc b/src/PiecedSegment.cc index 00c1f8af..31b3ad2d 100644 --- a/src/PiecedSegment.cc +++ b/src/PiecedSegment.cc @@ -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() {}