← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3333: Optimize searches with multiple extensions

 

------------------------------------------------------------
revno: 3333
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2013-08-02 21:13:38 +0200
message:
  Optimize searches with multiple extensions
modified:
  changelog.txt
  dcpp/ShareManager.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2013-08-01 20:36:42 +0000
+++ changelog.txt	2013-08-02 19:13:38 +0000
@@ -1,6 +1,7 @@
 * [L#1010996] Correct search responses (maksis, poy)
 * [L#1206658] Fix transfer painting issues (poy)
 * [L#1206855] Fix a bug with duplicate directory downloads (maksis)
+* Optimize searches with multiple extensions (emtee, poy)
 
 -- 0.828 2013-07-23 --
 * Translation fixes

=== modified file 'dcpp/ShareManager.cpp'
--- dcpp/ShareManager.cpp	2013-08-01 19:37:09 +0000
+++ dcpp/ShareManager.cpp	2013-08-02 19:13:38 +0000
@@ -47,6 +47,11 @@
 
 #include <limits>
 
+// define this to 1 to measure the time taken by searches to complete.
+#ifndef DCPP_TIME_SEARCHES
+#define DCPP_TIME_SEARCHES 0
+#endif
+
 namespace dcpp {
 
 using std::numeric_limits;
@@ -982,12 +987,12 @@
 		} else if(toCode('N', 'O') == cmd) {
 			exclude.emplace_back(p.substr(2));
 		} else if(toCode('E', 'X') == cmd) {
-			ext.push_back(p.substr(2));
+			ext.push_back(Text::toLower(p.substr(2)));
 		} else if(toCode('G', 'R') == cmd) {
 			auto exts = AdcHub::parseSearchExts(Util::toInt(p.substr(2)));
 			ext.insert(ext.begin(), exts.begin(), exts.end());
 		} else if(toCode('R', 'X') == cmd) {
-			noExt.push_back(p.substr(2));
+			noExt.push_back(Text::toLower(p.substr(2)));
 		} else if(toCode('G', 'E') == cmd) {
 			gt = Util::toInt64(p.substr(2));
 		} else if(toCode('L', 'E') == cmd) {
@@ -1047,11 +1052,8 @@
 		ext = StringList(ext.begin(), set_difference(ext.begin(), ext.end(), noExt.begin(), noExt.end(), ext.begin()));
 		noExt.clear();
 	}
-	for(auto& i: ext) {
-		if(name.size() >= i.size() && Util::stricmp(name.c_str() + name.size() - i.size(), i.c_str()) == 0)
-			return true;
-	}
-	return false;
+	auto fileExt = Util::getFileExt(name);
+	return !fileExt.empty() && std::find(ext.cbegin(), ext.cend(), Text::toLower(fileExt.substr(1))) != ext.cend();
 }
 
 /**
@@ -1160,10 +1162,24 @@
 }
 
 SearchResultList ShareManager::search(const StringList& adcParams, size_t maxResults) noexcept {
+#if DCPP_TIME_SEARCHES
+	auto start = GET_TICK();
+	ScopedFunctor(([start] {
+		LogManager::getInstance()->message("The ADC search took " + Util::toString(GET_TICK() - start) + " ms");
+	}));
+#endif
+
 	return search(SearchQuery(adcParams), maxResults);
 }
 
 SearchResultList ShareManager::search(const string& nmdcString, int searchType, int64_t size, int fileType, size_t maxResults) noexcept {
+#if DCPP_TIME_SEARCHES
+	auto start = GET_TICK();
+	ScopedFunctor(([start] {
+		LogManager::getInstance()->message("The NMDC search took " + Util::toString(GET_TICK() - start) + " ms");
+	}));
+#endif
+
 	return search(SearchQuery(nmdcString, searchType, size, fileType), maxResults);
 }