summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-01-11 13:37:46 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-01-11 13:37:46 +0000
commit1a4100cbc9c44ebc49cd76c989a5c5b188ea9ede (patch)
treeb97b899adc40f4a8f35321821f76d903a8985695 /src
parent5516bc02cb0099208f3f3efee92d8564014ff03a (diff)
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}
Diffstat (limited to 'src')
-rw-r--r--src/Piece.cc5
-rw-r--r--src/Piece.h1
-rw-r--r--src/PiecedSegment.cc2
3 files changed, 7 insertions, 1 deletions
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() {}