Advertisement
Guest User

Untitled

a guest
Jun 20th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1.  
  2. void ShareManager::Directory::search(SearchResultList& aResults, AdcSearch& aStrings, StringList::size_type maxResults) const noexcept {
  3. - StringSearch::List* cur = aStrings.include;
  4. StringSearch::List* old = aStrings.include;
  5.  
  6. unique_ptr<StringSearch::List> newStr;
  7.  
  8. // Find any matches in the directory name
  9. - for(auto& k: *cur) {
  10. - if(k.match(name) && !aStrings.isExcluded(name)) {
  11. + for(StringSearch::List::const_iterator k = aStrings.include->begin(); k != aStrings.include->end(); ++k) {
  12. + if(k->match(name) && !aStrings.isExcluded(name)) {
  13. if(!newStr.get()) {
  14. - newStr = unique_ptr<StringSearch::List>(new StringSearch::List(*cur));
  15. + newStr = unique_ptr<StringSearch::List>(new StringSearch::List(*aStrings.include));
  16. }
  17. - newStr->erase(remove(newStr->begin(), newStr->end(), k), newStr->end());
  18. + newStr->erase(remove(newStr->begin(), newStr->end(), *k), newStr->end());
  19. }
  20. }
  21.  
  22. if(newStr.get() != 0) {
  23. - cur = newStr.get();
  24. + aStrings.include = newStr.get();
  25. }
  26.  
  27. bool sizeOk = (aStrings.gt == 0);
  28. - if( cur->empty() && aStrings.ext.empty() && sizeOk ) {
  29. + if( aStrings.include->empty() && aStrings.ext.empty() && sizeOk ) {
  30. // We satisfied all the search words! Add the directory...
  31. SearchResultPtr sr(new SearchResult(SearchResult::TYPE_DIRECTORY, getSize(), getFullName(), TTHValue()));
  32. aResults.push_back(sr);
  33. @@ -1305,29 +1964,29 @@
  34. }
  35.  
  36. if(!aStrings.isDirectory) {
  37. - for(auto& i: files) {
  38. + for(File::Set::const_iterator i = files.begin(); i != files.end(); ++i) {
  39.  
  40. - if(!(i.getSize() >= aStrings.gt)) {
  41. + if(!(i->getSize() >= aStrings.gt)) {
  42. continue;
  43. - } else if(!(i.getSize() <= aStrings.lt)) {
  44. + } else if(!(i->getSize() <= aStrings.lt)) {
  45. continue;
  46. - }
  47. + }
  48.  
  49. - if(aStrings.isExcluded(i.getName()))
  50. + if(aStrings.isExcluded(i->getName()))
  51. continue;
  52.  
  53. - auto j = cur->begin();
  54. - for(; j != cur->end() && j->match(i.getName()); ++j)
  55. + StringSearch::List::const_iterator j = aStrings.include->begin();
  56. + for(; j != aStrings.include->end() && j->match(i->getName()); ++j)
  57. ; // Empty
  58.  
  59. - if(j != cur->end())
  60. + if(j != aStrings.include->end())
  61. continue;
  62.  
  63. // Check file type...
  64. - if(aStrings.hasExt(i.getName())) {
  65. + if(aStrings.hasExt(i->getName())) {
  66.  
  67. - SearchResultPtr sr(new SearchResult(SearchResult::TYPE_FILE,
  68. - i.getSize(), getFullName() + i.getName(), i.getTTH()));
  69. + SearchResultPtr sr(new SearchResult(SearchResult::TYPE_FILE,
  70. + i->getSize(), getFullName() + i->getName(), i->getTTH()));
  71. aResults.push_back(sr);
  72. ShareManager::getInstance()->addHits(1);
  73. if(aResults.size() >= maxResults) {
  74. @@ -1337,115 +1996,345 @@
  75. }
  76. }
  77.  
  78. - for(auto l = directories.begin(); (l != directories.end()) && (aResults.size() < maxResults); ++l) {
  79. + for(Directory::Map::const_iterator l = directories.begin(); (l != directories.end()) && (aResults.size() < maxResults); ++l) {
  80. l->second->search(aResults, aStrings, maxResults);
  81. }
  82. - aStrings.include = old;
  83. +
  84. + //faster to check this?
  85. + if (aStrings.include->size() != old->size())
  86. + aStrings.include = old;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement