diff options
author | David Kalnischkies <david@kalnischkies.de> | 2021-08-28 13:24:06 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2021-08-28 22:21:35 +0200 |
commit | b104891d015d0b8e152d8ac723027f824077948a (patch) | |
tree | 1718cad8c424f7e5058dbc2b05500f5e2a0ea8d1 /apt-pkg | |
parent | e267d1ee54e3e2a9478201192293f3f8c72e118c (diff) |
Simplify selection of highest source version providers
The old code is a bit longer and does a sort (N*log(N)) + find (at most N)
It is replaced by max_element (N) + remove_if (N). The practical
difference is minimal as the N we operate on is rather small, but the
replacement is hopefully easier to understand at a glance as well.
Gbp-Dch: Ignore
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/depcache.cc | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 2c3c6d01d..dfd1e1084 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -2308,7 +2308,7 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &Pkg, auto const sort_by_source_version = [](pkgCache::VerIterator const &A, pkgCache::VerIterator const &B) { auto const verret = A.Cache()->VS->CmpVersion(A.SourceVerStr(), B.SourceVerStr()); if (verret != 0) - return verret > 0; + return verret < 0; return A->ID < B->ID; }; @@ -2361,11 +2361,8 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &Pkg, // only latest binary package of a source package is marked instead of all for (auto &providers : providers_by_source) { - std::sort(providers.second.begin(), providers.second.end(), sort_by_source_version); - auto const highestSrcVer = (*providers.second.begin()).SourceVerStr(); - auto notThisVer = std::find_if_not(providers.second.begin(), providers.second.end(), [&](auto const &V) { return strcmp(highestSrcVer, V.SourceVerStr()) == 0; }); - if (notThisVer != providers.second.end()) - providers.second.erase(notThisVer, providers.second.end()); + auto const highestSrcVer = (*std::max_element(providers.second.begin(), providers.second.end(), sort_by_source_version)).SourceVerStr(); + providers.second.erase(std::remove_if(providers.second.begin(), providers.second.end(), [&](auto const &V) { return strcmp(highestSrcVer, V.SourceVerStr()) != 0; }), providers.second.end()); // if the provider is a versioned kernel package mark them only for protected kernels if (providers.second.size() == 1) continue; |