summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-12-17 13:20:53 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2021-01-04 10:43:31 +0100
commit290a4cf9455f45895718ed698147061fcd0a2dcb (patch)
tree43d1206720f1792b5b4a213c55eb996a5b142c4b
parent4215b6b2ce64f7bd0988c63c8d7d3e34833ec813 (diff)
depcache: Cache our InRootSetFunc
This avoids the cost of setting up the function every time we mark and sweep.
-rw-r--r--apt-pkg/depcache.cc26
-rw-r--r--apt-pkg/depcache.h6
2 files changed, 24 insertions, 8 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index c7ef7a400..3c9695d56 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -95,10 +95,14 @@ pkgDepCache::ActionGroup::~ActionGroup()
// DepCache::pkgDepCache - Constructors /*{{{*/
// ---------------------------------------------------------------------
/* */
-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),
- iBrokenCount(0), iPolicyBrokenCount(0), iBadCount(0), d(NULL)
+
+struct pkgDepCache::Private
+{
+ std::unique_ptr<InRootSetFunc> inRootSetFunc;
+};
+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),
+ iBrokenCount(0), iPolicyBrokenCount(0), iBadCount(0), d(new Private)
{
DebugMarker = _config->FindB("Debug::pkgDepCache::Marker", false);
DebugAutoInstall = _config->FindB("Debug::pkgDepCache::AutoInstall", false);
@@ -116,6 +120,7 @@ pkgDepCache::~pkgDepCache()
delete [] PkgState;
delete [] DepState;
delete delLocalPolicy;
+ delete d;
}
/*}}}*/
bool pkgDepCache::CheckConsistency(char const *const msgtag) /*{{{*/
@@ -2157,6 +2162,13 @@ pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc() /*{{{*/
return NULL;
}
}
+
+pkgDepCache::InRootSetFunc *pkgDepCache::GetCachedRootSetFunc()
+{
+ if (d->inRootSetFunc == nullptr)
+ d->inRootSetFunc.reset(GetRootSetFunc());
+ return d->inRootSetFunc.get();
+}
/*}}}*/
bool pkgDepCache::MarkFollowsRecommends()
{
@@ -2369,9 +2381,9 @@ bool pkgDepCache::MarkAndSweep(InRootSetFunc &rootFunc)
}
bool pkgDepCache::MarkAndSweep()
{
- std::unique_ptr<InRootSetFunc> f(GetRootSetFunc());
- if(f.get() != NULL)
- return MarkAndSweep(*f.get());
+ InRootSetFunc *f(GetCachedRootSetFunc());
+ if (f != NULL)
+ return MarkAndSweep(*f);
else
return false;
}
diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h
index 78f88ba2f..9a6019092 100644
--- a/apt-pkg/depcache.h
+++ b/apt-pkg/depcache.h
@@ -380,6 +380,9 @@ class APT_PUBLIC pkgDepCache : protected pkgCache::Namespace
*/
virtual InRootSetFunc *GetRootSetFunc();
+ /** This should return const really - do not delete. */
+ InRootSetFunc *GetCachedRootSetFunc() APT_HIDDEN;
+
/** \return \b true if the garbage collector should follow recommendations.
*/
virtual bool MarkFollowsRecommends();
@@ -516,7 +519,8 @@ class APT_PUBLIC pkgDepCache : protected pkgCache::Namespace
bool const rPurge, unsigned long const Depth, bool const FromUser);
private:
- void * const d;
+ struct Private;
+ Private *const d;
APT_HIDDEN bool MarkInstall_StateChange(PkgIterator const &Pkg, bool AutoInst, bool FromUser);
APT_HIDDEN bool MarkInstall_DiscardInstall(PkgIterator const &Pkg);