summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2025-07-24 22:08:52 +0200
committerJulian Andres Klode <jak@debian.org>2025-08-26 11:49:18 +0000
commit6abcb32f7df63c64b88a4fef57d38e219d2b6b42 (patch)
tree2dafe4ab2d7965cf38effd7876fc9e5a8eae4803 /apt-pkg
parent27a6bb49ea806e808bf6ebd849542bd32cf256c6 (diff)
debListParser: Cache `essential` and `myArch` more
Lookup these variables in the constructor once, rather than once per package. This requires a bit of care as debListParser::UsePackage() defaults to "all" for essential when unset, hence we simply change its == "all" comparisons to == "all" || .empty().# This removes any per-paragraph configuration lookups from the file parser. Also parse myArch from ParseProvides down to ParseDepends() as that call ended up causing it to query APT::Architecture *again* since the function we call is static. Together, the removed config lookups safe about 2.3% of cache generation runtime.
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/deb/deblistparser.cc19
-rw-r--r--apt-pkg/deb/deblistparser.h4
2 files changed, 10 insertions, 13 deletions
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index dfb07d2a6..b62c1a84f 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -63,6 +63,9 @@ debListParser::debListParser(FileFd *File) :
forceEssential.emplace_back("apt");
forceImportant = _config->FindVector("pkgCacheGen::ForceImportant");
myArch = _config->Find("APT::Architecture");
+ // Possible values are: "all", "native", "installed" and "none"
+ // The "installed" mode is handled by ParseStatus(), See #544481 and friends.
+ string const static essential = _config->Find("pkgCacheGen::Essential");
}
/*}}}*/
// ListParser::Package - Return the package name /*{{{*/
@@ -293,11 +296,7 @@ std::string_view debListParser::Description_md5()
bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg,
pkgCache::VerIterator &Ver)
{
- string const static myArch = _config->Find("APT::Architecture");
- // Possible values are: "all", "native", "installed" and "none"
- // The "installed" mode is handled by ParseStatus(), See #544481 and friends.
- string const static essential = _config->Find("pkgCacheGen::Essential", "all");
- if (essential == "all" ||
+ if (essential == "all" || essential.empty() ||
(essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()))
if (Section.FindFlag(pkgTagSection::Key::Essential,Pkg->Flags,pkgCache::Flag::Essential) == false)
return false;
@@ -309,7 +308,7 @@ bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg,
if (std::find(forceEssential.begin(), forceEssential.end(), Pkg.Name()) != forceEssential.end())
{
if ((essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()) ||
- essential == "all")
+ essential == "all" || essential.empty())
Pkg->Flags |= pkgCache::Flag::Essential | pkgCache::Flag::Important;
else
Pkg->Flags |= pkgCache::Flag::Important;
@@ -400,10 +399,8 @@ bool debStatusListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
if (Section.Find(pkgTagSection::Key::Status,Start,Stop) == false)
return true;
- // UsePackage() is responsible for setting the flag in the default case
- bool const static essential = _config->Find("pkgCacheGen::Essential", "") == "installed";
- if (essential == true &&
- Section.FindFlag(pkgTagSection::Key::Essential,Pkg->Flags,pkgCache::Flag::Essential) == false)
+ if (essential == "installed" &&
+ Section.FindFlag(pkgTagSection::Key::Essential, Pkg->Flags, pkgCache::Flag::Essential) == false)
return false;
// Isolate the first word
@@ -893,7 +890,7 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
do
{
- Start = ParseDepends(Start,Stop,Package,Version,Op, false, false, false);
+ Start = ParseDepends(Start, Stop, Package, Version, Op, false, false, false, myArch);
const size_t archfound = Package.rfind(':');
if (Start == 0)
return _error->Error("Problem parsing Provides line of %s:%s=%s", Ver.ParentPkg().Name(), Ver.Arch(), Ver.VerStr());
diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h
index ff1bfa06c..2a9108775 100644
--- a/apt-pkg/deb/deblistparser.h
+++ b/apt-pkg/deb/deblistparser.h
@@ -36,13 +36,13 @@ class APT_HIDDEN debListParser : public pkgCacheListParser
unsigned char Val;
};
- private:
+ protected:
std::vector<std::string> forceEssential;
std::vector<std::string> forceImportant;
std::string MD5Buffer;
std::string myArch;
+ std::string essential;
- protected:
pkgTagFile Tags;
pkgTagSection Section;
map_filesize_t iOffset;