Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ShareManager::Directory::search(SearchResultList& aResults, AdcSearch& aStrings, StringList::size_type maxResults) const noexcept {
- - StringSearch::List* cur = aStrings.include;
- StringSearch::List* old = aStrings.include;
- unique_ptr<StringSearch::List> newStr;
- // Find any matches in the directory name
- - for(auto& k: *cur) {
- - if(k.match(name) && !aStrings.isExcluded(name)) {
- + for(StringSearch::List::const_iterator k = aStrings.include->begin(); k != aStrings.include->end(); ++k) {
- + if(k->match(name) && !aStrings.isExcluded(name)) {
- if(!newStr.get()) {
- - newStr = unique_ptr<StringSearch::List>(new StringSearch::List(*cur));
- + newStr = unique_ptr<StringSearch::List>(new StringSearch::List(*aStrings.include));
- }
- - newStr->erase(remove(newStr->begin(), newStr->end(), k), newStr->end());
- + newStr->erase(remove(newStr->begin(), newStr->end(), *k), newStr->end());
- }
- }
- if(newStr.get() != 0) {
- - cur = newStr.get();
- + aStrings.include = newStr.get();
- }
- bool sizeOk = (aStrings.gt == 0);
- - if( cur->empty() && aStrings.ext.empty() && sizeOk ) {
- + if( aStrings.include->empty() && aStrings.ext.empty() && sizeOk ) {
- // We satisfied all the search words! Add the directory...
- SearchResultPtr sr(new SearchResult(SearchResult::TYPE_DIRECTORY, getSize(), getFullName(), TTHValue()));
- aResults.push_back(sr);
- @@ -1305,29 +1964,29 @@
- }
- if(!aStrings.isDirectory) {
- - for(auto& i: files) {
- + for(File::Set::const_iterator i = files.begin(); i != files.end(); ++i) {
- - if(!(i.getSize() >= aStrings.gt)) {
- + if(!(i->getSize() >= aStrings.gt)) {
- continue;
- - } else if(!(i.getSize() <= aStrings.lt)) {
- + } else if(!(i->getSize() <= aStrings.lt)) {
- continue;
- - }
- + }
- - if(aStrings.isExcluded(i.getName()))
- + if(aStrings.isExcluded(i->getName()))
- continue;
- - auto j = cur->begin();
- - for(; j != cur->end() && j->match(i.getName()); ++j)
- + StringSearch::List::const_iterator j = aStrings.include->begin();
- + for(; j != aStrings.include->end() && j->match(i->getName()); ++j)
- ; // Empty
- - if(j != cur->end())
- + if(j != aStrings.include->end())
- continue;
- // Check file type...
- - if(aStrings.hasExt(i.getName())) {
- + if(aStrings.hasExt(i->getName())) {
- - SearchResultPtr sr(new SearchResult(SearchResult::TYPE_FILE,
- - i.getSize(), getFullName() + i.getName(), i.getTTH()));
- + SearchResultPtr sr(new SearchResult(SearchResult::TYPE_FILE,
- + i->getSize(), getFullName() + i->getName(), i->getTTH()));
- aResults.push_back(sr);
- ShareManager::getInstance()->addHits(1);
- if(aResults.size() >= maxResults) {
- @@ -1337,115 +1996,345 @@
- }
- }
- - for(auto l = directories.begin(); (l != directories.end()) && (aResults.size() < maxResults); ++l) {
- + for(Directory::Map::const_iterator l = directories.begin(); (l != directories.end()) && (aResults.size() < maxResults); ++l) {
- l->second->search(aResults, aStrings, maxResults);
- }
- - aStrings.include = old;
- +
- + //faster to check this?
- + if (aStrings.include->size() != old->size())
- + aStrings.include = old;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement