summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-03-22 16:21:11 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-03-22 16:21:11 +0000
commit198b87fa3e564f6df1df8cbf961d655a59216d78 (patch)
tree7cb78607b7a14d28a8c1ccb53b98fb2fadbc98a9
parent26aa28acb3793d3d992625fcaad5e45df336a9a3 (diff)
* replaced std::vector with std::deque.
-rw-r--r--ChangeLog1
-rw-r--r--src/BitfieldMan.cc4
-rw-r--r--src/BitfieldMan.h6
-rw-r--r--src/CookieBox.cc10
-rw-r--r--src/CookieBox.h8
-rw-r--r--src/Dictionary.cc2
-rw-r--r--src/Dictionary.h7
-rw-r--r--src/Directory.h4
-rw-r--r--src/DownloadEngine.cc21
-rw-r--r--src/DownloadEngine.h15
-rw-r--r--src/HttpConnection.cc4
-rw-r--r--src/HttpHeader.cc4
-rw-r--r--src/HttpHeader.h4
-rw-r--r--src/HttpResponseCommand.cc4
-rw-r--r--src/List.h4
-rw-r--r--src/PeerInteractionCommand.cc10
-rw-r--r--src/PeerInteractionCommand.h1
-rw-r--r--src/PendingMessage.h4
-rw-r--r--src/Piece.cc2
-rw-r--r--src/Piece.h2
-rw-r--r--src/RequestSlotMan.h4
-rw-r--r--src/Segment.h4
-rw-r--r--src/SegmentMan.cc16
-rw-r--r--src/SegmentMan.h1
-rw-r--r--src/ShaVisitor.cc4
-rw-r--r--src/SplitFirstSegmentSplitter.cc2
-rw-r--r--src/SplitSlowestSegmentSplitter.cc4
-rw-r--r--src/TorrentMan.h10
-rw-r--r--src/Util.cc2
-rw-r--r--src/Util.h4
-rw-r--r--src/common.h4
-rw-r--r--src/main.cc8
32 files changed, 96 insertions, 84 deletions
diff --git a/ChangeLog b/ChangeLog
index 0a1c20d7..4663bb10 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,7 @@
* AbstractDiskWriter.{h,cc}: moved digest context initialization
to Constructor. Also, moved digest cleanup to Destructor.
* MetaFileUtil.cc: fixed memory leak
+ * replaced std::vector with std::deque.
2006-03-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc
index d0041fe6..66f89205 100644
--- a/src/BitfieldMan.cc
+++ b/src/BitfieldMan.cc
@@ -185,8 +185,8 @@ int BitfieldMan::getFirstMissingUnusedIndex() const {
return -1;
}
-vector<int> BitfieldMan::getAllMissingIndexes() const {
- vector<int> missingIndexes;
+BlockIndexes BitfieldMan::getAllMissingIndexes() const {
+ BlockIndexes missingIndexes;
for(int i = 0; i < bitfieldLength; i++) {
unsigned char bit = ~bitfield[i];
for(int bs = 7; bs >= 0 && i*8+7-bs < blocks; bs--) {
diff --git a/src/BitfieldMan.h b/src/BitfieldMan.h
index 28f2f026..ec8dcafc 100644
--- a/src/BitfieldMan.h
+++ b/src/BitfieldMan.h
@@ -23,7 +23,9 @@
#define _D_BITFIELD_MAN_H_
#include "common.h"
-#include <vector>
+#include <deque>
+
+typedef deque<int> BlockIndexes;
class BitfieldMan {
private:
@@ -63,7 +65,7 @@ public:
int getFirstMissingUnusedIndex(const unsigned char* bitfield, int len) const;
int getFirstMissingUnusedIndex() const;
int getMissingUnusedIndex(const unsigned char* bitfield, int len) const;
- vector<int> getAllMissingIndexes() const;
+ BlockIndexes getAllMissingIndexes() const;
int countMissingBlock() const;
bool setUseBit(int index);
bool unsetUseBit(int index);
diff --git a/src/CookieBox.cc b/src/CookieBox.cc
index 96d6e24c..1371afb0 100644
--- a/src/CookieBox.cc
+++ b/src/CookieBox.cc
@@ -54,18 +54,18 @@ void CookieBox::setField(Cookie& cookie, string name, string value) const {
void CookieBox::parse(Cookie& cookie, string cookieStr) const {
cookie.clear();
- vector<string> terms;
+ Strings terms;
Util::slice(terms, cookieStr, ';');
- for(vector<string>::iterator itr = terms.begin(); itr != terms.end(); itr++) {
+ for(Strings::iterator itr = terms.begin(); itr != terms.end(); itr++) {
pair<string, string> nv;
Util::split(nv, *itr, '=');
setField(cookie, nv.first, nv.second);
}
}
-vector<Cookie> CookieBox::criteriaFind(string host, string dir, bool secure) const {
- vector<Cookie> result;
- for(vector<Cookie>::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
+Cookies CookieBox::criteriaFind(string host, string dir, bool secure) const {
+ Cookies result;
+ for(Cookies::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
const Cookie& c = *itr;
if((secure || !c.secure && !secure) &&
Util::endsWith(host, c.domain) &&
diff --git a/src/CookieBox.h b/src/CookieBox.h
index 12c1f442..6892670a 100644
--- a/src/CookieBox.h
+++ b/src/CookieBox.h
@@ -24,7 +24,7 @@
#include "common.h"
#include <string>
-#include <vector>
+#include <deque>
using namespace std;
@@ -49,9 +49,11 @@ public:
}
};
+typedef deque<Cookie> Cookies;
+
class CookieBox {
private:
- vector<Cookie> cookies;
+ Cookies cookies;
void setField(Cookie& cookie, string name, string value) const;
public:
CookieBox();
@@ -60,7 +62,7 @@ public:
void add(const Cookie& cookie);
void add(string cookieStr);
void parse(Cookie& cookie, string cookieStr) const;
- vector<Cookie> criteriaFind(string host, string dir, bool secure) const;
+ Cookies criteriaFind(string host, string dir, bool secure) const;
};
#endif // _D_COOKIE_BOX_H_
diff --git a/src/Dictionary.cc b/src/Dictionary.cc
index 1c46323c..418979cd 100644
--- a/src/Dictionary.cc
+++ b/src/Dictionary.cc
@@ -52,6 +52,6 @@ void Dictionary::accept(MetaEntryVisitor* v) const {
v->visit(this);
}
-const vector<string>& Dictionary::getOrder() const {
+const Order& Dictionary::getOrder() const {
return order;
}
diff --git a/src/Dictionary.h b/src/Dictionary.h
index 07837741..1bbb3c1f 100644
--- a/src/Dictionary.h
+++ b/src/Dictionary.h
@@ -24,17 +24,18 @@
#include "MetaEntry.h"
#include <map>
-#include <vector>
+#include <deque>
#include <string>
using namespace std;
typedef map<string, MetaEntry*> MetaTable;
+typedef deque<string> Order;
class Dictionary : public MetaEntry {
private:
MetaTable table;
- vector<string> order;
+ Order order;
void clearTable();
public:
Dictionary();
@@ -44,7 +45,7 @@ public:
void put(string name, MetaEntry* entry);
void accept(MetaEntryVisitor* v) const;
- const vector<string>& getOrder() const;
+ const Order& getOrder() const;
};
diff --git a/src/Directory.h b/src/Directory.h
index 700aa441..784c9e2e 100644
--- a/src/Directory.h
+++ b/src/Directory.h
@@ -24,11 +24,11 @@
#include "common.h"
#include <string>
-#include <vector>
+#include <deque>
class Directory {
-typedef vector<Directory*> Files;
+typedef deque<Directory*> Files;
private:
string name;
diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc
index 57bdb831..42059e0f 100644
--- a/src/DownloadEngine.cc
+++ b/src/DownloadEngine.cc
@@ -75,14 +75,13 @@ void DownloadEngine::waitData() {
FD_ZERO(&rfds);
FD_ZERO(&wfds);
int max = 0;
- for(vector<Socket*>::iterator itr = rsockets.begin(); itr != rsockets.end(); itr++) {
+ for(Sockets::iterator itr = rsockets.begin(); itr != rsockets.end(); itr++) {
FD_SET((*itr)->getSockfd(), &rfds);
if(max < (*itr)->getSockfd()) {
max = (*itr)->getSockfd();
}
}
- for(vector<Socket*>::iterator itr = wsockets.begin(); itr != wsockets.end(); itr++) {
-
+ for(Sockets::iterator itr = wsockets.begin(); itr != wsockets.end(); itr++) {
FD_SET((*itr)->getSockfd(), &wfds);
if(max < (*itr)->getSockfd()) {
max = (*itr)->getSockfd();
@@ -94,10 +93,10 @@ void DownloadEngine::waitData() {
retval = select(max+1, &rfds, /*&wfds*/NULL, NULL, &tv);
}
-bool DownloadEngine::addSocket(vector<Socket*>& sockets, Socket* socket) {
- vector<Socket*>::iterator itr = find(sockets.begin(),
- sockets.end(),
- socket);
+bool DownloadEngine::addSocket(Sockets& sockets, Socket* socket) {
+ Sockets::iterator itr = find(sockets.begin(),
+ sockets.end(),
+ socket);
if(itr == sockets.end()) {
sockets.push_back(socket);
return true;
@@ -106,10 +105,10 @@ bool DownloadEngine::addSocket(vector<Socket*>& sockets, Socket* socket) {
}
}
-bool DownloadEngine::deleteSocket(vector<Socket*>& sockets, Socket* socket) {
- vector<Socket*>::iterator itr = find(sockets.begin(),
- sockets.end(),
- socket);
+bool DownloadEngine::deleteSocket(Sockets& sockets, Socket* socket) {
+ Sockets::iterator itr = find(sockets.begin(),
+ sockets.end(),
+ socket);
if(itr != sockets.end()) {
sockets.erase(itr);
return true;
diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h
index 1a9fc742..10e9dffa 100644
--- a/src/DownloadEngine.h
+++ b/src/DownloadEngine.h
@@ -23,7 +23,7 @@
#define _D_DOWNLOAD_ENGINE_H_
#include <queue>
-#include <vector>
+#include <deque>
#include "Command.h"
#include "Socket.h"
#include "SegmentMan.h"
@@ -35,22 +35,25 @@
using namespace std;
+typedef deque<Socket*> Sockets;
+typedef queue<Command*> Commands;
+
class DownloadEngine {
private:
void waitData();
- vector<Socket*> rsockets;
- vector<Socket*> wsockets;
+ Sockets rsockets;
+ Sockets wsockets;
void shortSleep() const;
- bool addSocket(vector<Socket*>& sockets, Socket* socket);
- bool deleteSocket(vector<Socket*>& sockets, Socket* socket);
+ bool addSocket(Sockets& sockets, Socket* socket);
+ bool deleteSocket(Sockets& sockets, Socket* socket);
protected:
virtual void initStatistics() = 0;
virtual void calculateStatistics() = 0;
virtual void onEndOfRun() = 0;
public:
bool noWait;
- queue<Command*> commands;
+ Commands commands;
SegmentMan* segmentMan;
DiskWriter* diskWriter;
const Logger* logger;
diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc
index f93faead..db6b1848 100644
--- a/src/HttpConnection.cc
+++ b/src/HttpConnection.cc
@@ -90,8 +90,8 @@ string HttpConnection::createRequest(const Segment& segment) const {
}
string cookiesValue;
- vector<Cookie> cookies = req->cookieBox->criteriaFind(req->getHost(), req->getDir(), req->getProtocol() == "https" ? true : false);
- for(vector<Cookie>::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
+ Cookies cookies = req->cookieBox->criteriaFind(req->getHost(), req->getDir(), req->getProtocol() == "https" ? true : false);
+ for(Cookies::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
cookiesValue += (*itr).toString()+";";
}
if(cookiesValue.size()) {
diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc
index eb80cf5b..fa61056c 100644
--- a/src/HttpHeader.cc
+++ b/src/HttpHeader.cc
@@ -39,8 +39,8 @@ string HttpHeader::getFirst(const string& name) const {
}
}
-vector<string> HttpHeader::get(const string& name) const {
- vector<string> v;
+Strings HttpHeader::get(const string& name) const {
+ Strings v;
for(multimap<string, string>::const_iterator itr = table.find(name); itr != table.end(); itr++) {
v.push_back((*itr).second);
}
diff --git a/src/HttpHeader.h b/src/HttpHeader.h
index 3f7fc550..20be3098 100644
--- a/src/HttpHeader.h
+++ b/src/HttpHeader.h
@@ -24,7 +24,7 @@
#include "common.h"
#include <map>
-#include <vector>
+#include <deque>
#include <string>
using namespace std;
@@ -39,7 +39,7 @@ public:
void put(const string& name, const string& value);
bool defined(const string& name) const;
string getFirst(const string& name) const;
- vector<string> get(const string& name) const;
+ Strings get(const string& name) const;
int getFirstAsInt(const string& name) const;
long long int getFirstAsLLInt(const string& name) const;
};
diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc
index 48783d24..d6717d15 100644
--- a/src/HttpResponseCommand.cc
+++ b/src/HttpResponseCommand.cc
@@ -159,8 +159,8 @@ void HttpResponseCommand::createHttpDownloadCommand(string transferEncoding) {
}
void HttpResponseCommand::retrieveCookie(const HttpHeader& headers) {
- vector<string> v = headers.get("Set-Cookie");
- for(vector<string>::const_iterator itr = v.begin(); itr != v.end(); itr++) {
+ Strings v = headers.get("Set-Cookie");
+ for(Strings::const_iterator itr = v.begin(); itr != v.end(); itr++) {
Cookie c;
req->cookieBox->parse(c, *itr);
req->cookieBox->add(c);
diff --git a/src/List.h b/src/List.h
index 64c2a462..dee96a8c 100644
--- a/src/List.h
+++ b/src/List.h
@@ -23,11 +23,11 @@
#define _D_LIST_H_
#include "MetaEntry.h"
-#include <vector>
+#include <deque>
using namespace std;
-typedef vector<MetaEntry*> MetaList;
+typedef deque<MetaEntry*> MetaList;
class List : public MetaEntry {
private:
diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc
index 5b0174ee..0b5a2b8a 100644
--- a/src/PeerInteractionCommand.cc
+++ b/src/PeerInteractionCommand.cc
@@ -317,9 +317,9 @@ void PeerInteractionCommand::createRequestPendingMessage(int blockIndex) {
void PeerInteractionCommand::sendMessages() {
if(!Piece::isNull(piece) && !peer->peerChoking) {
if(e->torrentMan->isEndGame()) {
- vector<int> missingBlockIndexes = piece.getAllMissingBlockIndexes();
+ BlockIndexes missingBlockIndexes = piece.getAllMissingBlockIndexes();
if(requestSlotMan->isEmpty()) {
- for(vector<int>::const_iterator itr = missingBlockIndexes.begin();
+ for(PieceIndexes::const_iterator itr = missingBlockIndexes.begin();
itr != missingBlockIndexes.end(); itr++) {
createRequestPendingMessage(*itr);
}
@@ -374,17 +374,17 @@ void PeerInteractionCommand::beforeSocketCheck() {
if(sequence == WIRED) {
e->torrentMan->unadvertisePiece(cuid);
- vector<int> indexes = e->torrentMan->getAdvertisedPieceIndexes(cuid);
+ PieceIndexes indexes = e->torrentMan->getAdvertisedPieceIndexes(cuid);
if(indexes.size() >= 20) {
PendingMessage pendingMessage(PeerMessage::BITFIELD, peerConnection);
pendingMessages.push_back(pendingMessage);
} else {
if(pendingMessages.size() == 0) {
- for(vector<int>::iterator itr = indexes.begin(); itr != indexes.end(); itr++) {
+ for(PieceIndexes::iterator itr = indexes.begin(); itr != indexes.end(); itr++) {
peerConnection->sendHave(*itr);
}
} else {
- for(vector<int>::iterator itr = indexes.begin(); itr != indexes.end(); itr++) {
+ for(PieceIndexes::iterator itr = indexes.begin(); itr != indexes.end(); itr++) {
PendingMessage pendingMessage = PendingMessage::createHaveMessage(*itr, peerConnection);
pendingMessages.push_back(pendingMessage);
}
diff --git a/src/PeerInteractionCommand.h b/src/PeerInteractionCommand.h
index 0bfe7e97..92f390df 100644
--- a/src/PeerInteractionCommand.h
+++ b/src/PeerInteractionCommand.h
@@ -26,7 +26,6 @@
#include "PeerConnection.h"
#include "PendingMessage.h"
#include "RequestSlotMan.h"
-#include <vector>
using namespace std;
diff --git a/src/PendingMessage.h b/src/PendingMessage.h
index da877748..3b542282 100644
--- a/src/PendingMessage.h
+++ b/src/PendingMessage.h
@@ -24,7 +24,7 @@
#include "common.h"
#include "PeerConnection.h"
-#include <vector>
+#include <deque>
class PendingMessage {
private:
@@ -66,6 +66,6 @@ public:
static PendingMessage createHaveMessage(int index, PeerConnection* peerConnectioin);
};
-typedef vector<PendingMessage> PendingMessages;
+typedef deque<PendingMessage> PendingMessages;
#endif // _D_PENDING_MESSAGE_H_
diff --git a/src/Piece.cc b/src/Piece.cc
index b27cc621..d4a36972 100644
--- a/src/Piece.cc
+++ b/src/Piece.cc
@@ -79,6 +79,6 @@ int Piece::getMissingUnusedBlockIndex() const {
return blockIndex;
}
-vector<int> Piece::getAllMissingBlockIndexes() const {
+BlockIndexes Piece::getAllMissingBlockIndexes() const {
return bitfield->getAllMissingIndexes();
}
diff --git a/src/Piece.h b/src/Piece.h
index f12dcf15..d8d7d95d 100644
--- a/src/Piece.h
+++ b/src/Piece.h
@@ -45,7 +45,7 @@ public:
Piece& operator=(const Piece& piece);
int getMissingUnusedBlockIndex() const;
- vector<int> getAllMissingBlockIndexes() const;
+ BlockIndexes getAllMissingBlockIndexes() const;
void completeBlock(int blockIndex);
void cancelBlock(int blockIndex);
int countCompleteBlock() const {
diff --git a/src/RequestSlotMan.h b/src/RequestSlotMan.h
index f0c1f008..2269651d 100644
--- a/src/RequestSlotMan.h
+++ b/src/RequestSlotMan.h
@@ -29,11 +29,11 @@
#include "PeerConnection.h"
#include "PendingMessage.h"
#include "TorrentMan.h"
-#include <vector>
+#include <deque>
#define DEFAULT_TIME_OUT 120
-typedef vector<RequestSlot> RequestSlots;
+typedef deque<RequestSlot> RequestSlots;
class RequestSlotMan {
private:
diff --git a/src/Segment.h b/src/Segment.h
index 21db6de3..dc2ea084 100644
--- a/src/Segment.h
+++ b/src/Segment.h
@@ -23,7 +23,7 @@
#define _D_SEGMENT_H_
#include "common.h"
-#include <vector>
+#include <deque>
using namespace std;
@@ -45,7 +45,7 @@ typedef struct {
bool finish;
} Segment;
-typedef vector<Segment> Segments;
+typedef deque<Segment> Segments;
#define SEGMENT_EQUAL(X, Y) (X.cuid == Y.cuid && X.sp == Y.sp && X.ep == Y.ep && X.ds == Y.ds && X.finish == Y.finish ? true : false)
diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc
index 57accd15..c2761796 100644
--- a/src/SegmentMan.cc
+++ b/src/SegmentMan.cc
@@ -35,7 +35,7 @@ SegmentMan::SegmentMan():totalSize(0),isSplittable(true),downloadStarted(false),
SegmentMan::~SegmentMan() {}
void SegmentMan::unregisterId(int cuid) {
- for(vector<Segment>::iterator itr = segments.begin(); itr != segments.end(); itr++) {
+ for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) {
if((*itr).cuid == cuid) {
cuid = 0;
}
@@ -57,7 +57,7 @@ bool SegmentMan::getSegment(Segment& seg, int cuid) {
segments.push_back(seg);
return true;
}
- for(vector<Segment>::iterator itr = segments.begin(); itr != segments.end(); itr++) {
+ for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) {
if((*itr).cuid == cuid && !(*itr).finish) {
// logger->debug("return an existing segment { "
// "sp = "+Util::ulitos((*itr).sp)+", "+
@@ -71,7 +71,7 @@ bool SegmentMan::getSegment(Segment& seg, int cuid) {
if(!isSplittable) {
return false;
}
- for(vector<Segment>::iterator itr = segments.begin(); itr != segments.end(); itr++) {
+ for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) {
Segment& s = *itr;
if(s.finish) {
continue;
@@ -86,7 +86,7 @@ bool SegmentMan::getSegment(Segment& seg, int cuid) {
}
void SegmentMan::updateSegment(const Segment& segment) {
- for(vector<Segment>::iterator itr = segments.begin(); itr != segments.end(); itr++) {
+ for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) {
if((*itr).cuid == segment.cuid &&
(*itr).sp == segment.sp &&
(*itr).ep == segment.ep) {
@@ -122,7 +122,7 @@ void SegmentMan::load() {
read(segFile);
fclose(segFile);
logger->info(MSG_LOADED_SEGMENT_FILE);
- for(vector<Segment>::iterator itr = segments.begin(); itr != segments.end();
+ for(Segments::iterator itr = segments.begin(); itr != segments.end();
itr++) {
(*itr).cuid = 0;
}
@@ -138,7 +138,7 @@ void SegmentMan::save() const {
if(fwrite(&totalSize, sizeof(totalSize), 1, segFile) < 1) {
throw new DlAbortEx(strerror(errno));
}
- for(vector<Segment>::const_iterator itr = segments.begin(); itr != segments.end(); itr++) {
+ for(Segments::const_iterator itr = segments.begin(); itr != segments.end(); itr++) {
if(fwrite(&*itr, sizeof(Segment), 1, segFile) < 1) {
throw new DlAbortEx(strerror(errno));
}
@@ -187,7 +187,7 @@ bool SegmentMan::finished() const {
if(!downloadStarted || segments.size() == 0) {
return false;
}
- for(vector<Segment>::const_iterator itr = segments.begin(); itr != segments.end(); itr++) {
+ for(Segments::const_iterator itr = segments.begin(); itr != segments.end(); itr++) {
if(!(*itr).finish) {
return false;
}
@@ -203,7 +203,7 @@ void SegmentMan::removeIfFinished() const {
long long int SegmentMan::getDownloadedSize() const {
long long int size = 0;
- for(vector<Segment>::const_iterator itr = segments.begin(); itr != segments.end(); itr++) {
+ for(Segments::const_iterator itr = segments.begin(); itr != segments.end(); itr++) {
size += (*itr).ds;
}
return size;
diff --git a/src/SegmentMan.h b/src/SegmentMan.h
index 970a4fd0..857a38f7 100644
--- a/src/SegmentMan.h
+++ b/src/SegmentMan.h
@@ -22,7 +22,6 @@
#ifndef _D_SEGMENT_MAN_H_
#define _D_SEGMENT_MAN_H_
-#include <vector>
#include "common.h"
#include "Logger.h"
#include "Segment.h"
diff --git a/src/ShaVisitor.cc b/src/ShaVisitor.cc
index b568051d..c443a869 100644
--- a/src/ShaVisitor.cc
+++ b/src/ShaVisitor.cc
@@ -54,8 +54,8 @@ void ShaVisitor::visit(const Data* d) {
void ShaVisitor::visit(const Dictionary* d) {
#ifdef HAVE_LIBSSL
EVP_DigestUpdate(&ctx, "d", 1);
- const vector<string>& v = d->getOrder();
- for(vector<string>::const_iterator itr = v.begin(); itr != v.end(); itr++) {
+ const Order& v = d->getOrder();
+ for(Order::const_iterator itr = v.begin(); itr != v.end(); itr++) {
string lenStr = Util::llitos(itr->size());
EVP_DigestUpdate(&ctx, lenStr.c_str(), lenStr.size());
EVP_DigestUpdate(&ctx, ":", 1);
diff --git a/src/SplitFirstSegmentSplitter.cc b/src/SplitFirstSegmentSplitter.cc
index 72a3f2d1..22e02da0 100644
--- a/src/SplitFirstSegmentSplitter.cc
+++ b/src/SplitFirstSegmentSplitter.cc
@@ -22,7 +22,7 @@
#include "SplitFirstSegmentSplitter.h"
bool SplitFirstSegmentSplitter::splitSegment(Segment& seg, int cuid, Segments& segments) {
- for(vector<Segment>::iterator itr = segments.begin(); itr != segments.end(); itr++) {
+ for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) {
Segment& s = *itr;
if(s.finish) {
continue;
diff --git a/src/SplitSlowestSegmentSplitter.cc b/src/SplitSlowestSegmentSplitter.cc
index 47c571bf..1be620e8 100644
--- a/src/SplitSlowestSegmentSplitter.cc
+++ b/src/SplitSlowestSegmentSplitter.cc
@@ -22,8 +22,8 @@
#include "SplitSlowestSegmentSplitter.h"
bool SplitSlowestSegmentSplitter::splitSegment(Segment& seg, int cuid, Segments& segments) {
- vector<Segment>::iterator slowest = segments.end();;
- for(vector<Segment>::iterator itr = segments.begin(); itr != segments.end(); itr++) {
+ Segments::iterator slowest = segments.end();;
+ for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) {
Segment& s = *itr;
if(s.finish) {
continue;
diff --git a/src/TorrentMan.h b/src/TorrentMan.h
index 2d25c250..92221293 100644
--- a/src/TorrentMan.h
+++ b/src/TorrentMan.h
@@ -30,7 +30,6 @@
#include "Piece.h"
#include "Directory.h"
#include <deque>
-#include <vector>
#include <map>
#include <string>
@@ -59,15 +58,16 @@ public:
typedef deque<Peer*> Peers;
typedef multimap<int, int> Haves;
-typedef vector<FileEntry> MultiFileEntries;
+typedef deque<FileEntry> MultiFileEntries;
typedef deque<Piece> UsedPieces;
+typedef deque<int> PieceIndexes;
class TorrentMan {
private:
Peers peers;
BitfieldMan* bitfield;
unsigned char infoHash[INFO_HASH_LENGTH];
- vector<string> pieceHashes;
+ deque<string> pieceHashes;
int peerEntryIdCounter;
int cuidCounter;
long long int downloadedSize;
@@ -151,8 +151,8 @@ public:
haves.insert(vt);
}
- vector<int> getAdvertisedPieceIndexes(int myCuid) const {
- vector<int> indexes;
+ PieceIndexes getAdvertisedPieceIndexes(int myCuid) const {
+ PieceIndexes indexes;
for(Haves::const_iterator itr = haves.begin(); itr != haves.end(); itr++) {
const Haves::value_type& have = *itr;
if(have.first == myCuid) {
diff --git a/src/Util.cc b/src/Util.cc
index b0a03f51..bd18037d 100644
--- a/src/Util.cc
+++ b/src/Util.cc
@@ -89,7 +89,7 @@ long long int Util::difftv(struct timeval tv1, struct timeval tv2) {
tv1.tv_usec-tv2.tv_usec);
}
-void Util::slice(vector<string>& result, string src, char delim) {
+void Util::slice(Strings& result, string src, char delim) {
string::size_type p = 0;
while(1) {
string::size_type np = src.find(delim, p);
diff --git a/src/Util.h b/src/Util.h
index f8e50932..b3244df6 100644
--- a/src/Util.h
+++ b/src/Util.h
@@ -25,7 +25,7 @@
#include "common.h"
#include <string>
#include <utility>
-#include <vector>
+#include <deque>
#include <sys/time.h>
using namespace std;
@@ -47,7 +47,7 @@ public:
* Take a string src which is a deliminated list and add its elements
* into result. result is not cleared before conversion begins.
*/
- static void slice(vector<string>& result, string src, char delim);
+ static void slice(Strings& result, string src, char delim);
static string trim(string src);
diff --git a/src/common.h b/src/common.h
index 1260edf5..af36936c 100644
--- a/src/common.h
+++ b/src/common.h
@@ -27,6 +27,8 @@
#include <iostream>
#include <assert.h>
#include <limits.h>
+#include <string>
+#include <deque>
#if ENABLE_NLS
# include <gettext.h>
# define _(String) gettext (String)
@@ -45,4 +47,6 @@
using namespace std;
+typedef deque<string> Strings;
+
#endif // _D_COMMON_H_
diff --git a/src/main.cc b/src/main.cc
index 58257eaf..27987f00 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -35,7 +35,7 @@
#include "PeerListenCommand.h"
#include "TorrentAutoSaveCommand.h"
#include "SleepCommand.h"
-#include <vector>
+#include <deque>
#include <algorithm>
#include <time.h>
#include <signal.h>
@@ -54,6 +54,8 @@ extern int optind, opterr, optopt;
using namespace std;
+typedef deque<Request*> Requests;
+
void printDownloadCompeleteMessage(string filename) {
printf(_("\nThe download was complete. <%s>\n"), filename.c_str());
}
@@ -94,7 +96,7 @@ void torrentHandler(int signal) {
exit(0);
}
-void addCommand(int cuid, const char* url, string referer, vector<Request*> requests) {
+void addCommand(int cuid, const char* url, string referer, Requests requests) {
Request* req = new Request();
req->setReferer(referer);
if(req->setUrl(url)) {
@@ -520,7 +522,7 @@ int main(int argc, char* argv[]) {
e->segmentMan->option = op;
e->segmentMan->splitter = splitter;
- vector<Request*> requests;
+ Requests requests;
for(int i = 1; optind+i-1 < argc; i++) {
for(int s = 1; s <= split; s++) {
addCommand(split*(i-1)+s, argv[optind+i-1], referer, requests);