From 6f01e7cc0c6f231711b3b81a81beb3775f0a855a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 18 Mar 2021 19:08:48 +0100 Subject: Store versioned kernel package detectors in d-pointer They are kinda costly, so it makes more sense to keep them around in private storage rather than generate them all the time in the MarkPackage method. We do keep them lazy through as we have that implemented already. --- apt-pkg/depcache.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index a958e6c76..2c3c6d01d 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -126,6 +126,7 @@ struct pkgDepCache::Private { std::unique_ptr inRootSetFunc; std::vector fullyExplored; + std::unique_ptr IsAVersionedKernelPackage, IsProtectedKernelPackage; }; pkgDepCache::pkgDepCache(pkgCache *const pCache, Policy *const Plcy) : group_level(0), Cache(pCache), PkgState(0), DepState(0), iUsrSize(0), iDownloadSize(0), iInstCount(0), iDelCount(0), iKeepCount(0), @@ -2304,7 +2305,6 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &Pkg, std::clog << "Marking: " << Pkg.FullName() << " " << Ver.VerStr() << " (" << reason << ")" << std::endl; - std::unique_ptr IsAVersionedKernelPackage, IsProtectedKernelPackage; 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) @@ -2369,8 +2369,8 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &Pkg, // if the provider is a versioned kernel package mark them only for protected kernels if (providers.second.size() == 1) continue; - if (not IsAVersionedKernelPackage) - IsAVersionedKernelPackage = [&]() -> std::unique_ptr { + if (not d->IsAVersionedKernelPackage) + d->IsAVersionedKernelPackage = [&]() -> std::unique_ptr { auto const patterns = _config->FindVector("APT::VersionedKernelPackages"); if (patterns.empty()) return std::make_unique(); @@ -2380,15 +2380,15 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &Pkg, regex << patterns.back() << "-.*$"; return std::make_unique(regex.str()); }(); - if (not std::all_of(providers.second.begin(), providers.second.end(), [&](auto const &Prv) { return (*IsAVersionedKernelPackage)(Prv.ParentPkg()); })) + if (not std::all_of(providers.second.begin(), providers.second.end(), [&](auto const &Prv) { return (*d->IsAVersionedKernelPackage)(Prv.ParentPkg()); })) continue; // … if there is at least one for protected kernels installed - if (not IsProtectedKernelPackage) - IsProtectedKernelPackage = APT::KernelAutoRemoveHelper::GetProtectedKernelsFilter(Cache); - if (not std::any_of(providers.second.begin(), providers.second.end(), [&](auto const &Prv) { return (*IsProtectedKernelPackage)(Prv.ParentPkg()); })) + if (not d->IsProtectedKernelPackage) + d->IsProtectedKernelPackage = APT::KernelAutoRemoveHelper::GetProtectedKernelsFilter(Cache); + if (not std::any_of(providers.second.begin(), providers.second.end(), [&](auto const &Prv) { return (*d->IsProtectedKernelPackage)(Prv.ParentPkg()); })) continue; providers.second.erase(std::remove_if(providers.second.begin(), providers.second.end(), - [&](auto const &Prv) { return not((*IsProtectedKernelPackage)(Prv.ParentPkg())); }), + [&](auto const &Prv) { return not((*d->IsProtectedKernelPackage)(Prv.ParentPkg())); }), providers.second.end()); } -- cgit v1.2.3-70-g09d2