aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2017-08-07 18:58:12 -0700
committerAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2017-08-07 18:58:12 -0700
commit1288dd799f3502f7201fc88d93ae69a1869d06fa (patch)
tree83b65a951a23328609a63194fe42244b26ba1170
parentf11e1ecb81480777d5bbb3f6fcde6d6bf6c762c2 (diff)
downloadpaludis-1288dd799f3502f7201fc88d93ae69a1869d06fa.tar.gz
paludis-1288dd799f3502f7201fc88d93ae69a1869d06fa.tar.xz
fuzzy-finder: convert to c++11, hoist check
Hoist the length check out of the loop. This avoids an unnecessary call each iteration through the loop. Use some C++11 constructs to simplify the logic a bit.
-rw-r--r--paludis/fuzzy_finder.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/paludis/fuzzy_finder.cc b/paludis/fuzzy_finder.cc
index 0768298..192e39c 100644
--- a/paludis/fuzzy_finder.cc
+++ b/paludis/fuzzy_finder.cc
@@ -95,14 +95,15 @@ namespace
const std::shared_ptr<const RepositoryNameSet> &,
const std::shared_ptr<const QualifiedPackageNameSet> & pkgs) const
{
- std::shared_ptr<QualifiedPackageNameSet> result(std::make_shared<QualifiedPackageNameSet>());
-
- for (QualifiedPackageNameSet::ConstIterator p(pkgs->begin()),
- p_end(pkgs->end()); p_end != p; ++p)
- if (((_package.length() >= 3) && (std::string::npos != stringify(p->package()).find(_package))) || (
- tolower(p->package().value()[0]) == _first_char &&
- _distance_calculator.distance_with(tolower_0_cost(p->package().value())) <= _threshold))
- result->insert(*p);
+ auto result = std::make_shared<QualifiedPackageNameSet>();
+ if (_package.length() < 3)
+ return result;
+
+ for (const auto & p : *pkgs)
+ if ((std::string::npos != stringify(p.package()).find(_package)) || (
+ tolower(p.package().value()[0]) == _first_char &&
+ _distance_calculator.distance_with(tolower_0_cost(p.package().value())) <= _threshold))
+ result->insert(p);
return result;
}