2009-05-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Use std::binary_search instead of std::find
	* src/DefaultPieceStorage.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-05-10 15:09:49 +00:00
parent 1d2cfd93d7
commit 52312c7a31
2 changed files with 6 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2009-05-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use std::binary_search instead of std::find
* src/DefaultPieceStorage.cc
2009-05-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-05-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed unnecessary BDE() call; leave them to implicit conversion. Removed unnecessary BDE() call; leave them to implicit conversion.

View File

@ -440,14 +440,13 @@ void DefaultPieceStorage::setFileFilter(const std::deque<std::string>& filePaths
void DefaultPieceStorage::setFileFilter(IntSequence seq) void DefaultPieceStorage::setFileFilter(IntSequence seq)
{ {
std::deque<int32_t> fileIndexes = seq.flush(); std::deque<int32_t> fileIndexes = seq.flush();
// TODO Is sorting necessary?
std::sort(fileIndexes.begin(), fileIndexes.end()); std::sort(fileIndexes.begin(), fileIndexes.end());
fileIndexes.erase(std::unique(fileIndexes.begin(), fileIndexes.end()), fileIndexes.end()); fileIndexes.erase(std::unique(fileIndexes.begin(), fileIndexes.end()), fileIndexes.end());
std::deque<std::string> filePaths; std::deque<std::string> filePaths;
const FileEntries& entries = diskAdaptor->getFileEntries(); const FileEntries& entries = diskAdaptor->getFileEntries();
int32_t entriesSize = entries.size(); int32_t entriesSize = entries.size();
for(int32_t i = 0; i < entriesSize; i++) { for(int32_t i = 0; i < entriesSize; i++) {
if(std::find(fileIndexes.begin(), fileIndexes.end(), i+1) != fileIndexes.end()) { if(std::binary_search(fileIndexes.begin(), fileIndexes.end(), i+1)) {
logger->debug("index=%d is %s", i+1, entries[i]->getPath().c_str()); logger->debug("index=%d is %s", i+1, entries[i]->getPath().c_str());
filePaths.push_back(entries[i]->getPath()); filePaths.push_back(entries[i]->getPath());
} }