summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHerman Semenoff <GermanAizek@yandex.ru>2026-04-08 11:51:08 +0300
committerJulian Andres Klode <jak@debian.org>2026-04-08 10:40:55 +0000
commitef70431f02e2ec13ecedab7ac342574e52d1877b (patch)
treede51c6f3ce74d0b7fd1ddacd0812cd1cbe116c14
parent5b649fb72ecdced056fb3daab02e88933cc7a32a (diff)
apt: push to emplace C++11 if possible
References: - https://www.reddit.com/r/cpp_questions/comments/pm63yx/why_clangtidy_says_use_emplace_back_instead_of/ - https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-emplace.html
-rw-r--r--apt-pkg/contrib/fileutl.cc2
-rw-r--r--apt-pkg/contrib/strutl.cc2
-rw-r--r--apt-pkg/deb/dpkgpm.cc16
-rw-r--r--apt-pkg/solver3.cc14
-rw-r--r--apt-private/private-install.cc8
-rw-r--r--cmdline/apt-cache.cc8
-rw-r--r--methods/rred.cc4
7 files changed, 27 insertions, 27 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 69e6dc430..74f5ec8bc 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -3091,7 +3091,7 @@ std::vector<std::string> Glob(std::string const &pattern, int flags)
// append results
for(i=0;i<globbuf.gl_pathc;i++)
- result.push_back(string(globbuf.gl_pathv[i]));
+ result.emplace_back(globbuf.gl_pathv[i]);
globfree(&globbuf);
return result;
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 4363ab818..bfd4967f5 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -1335,7 +1335,7 @@ vector<string> VectorizeString(string_view const &haystack, char const &split)
auto end = start;
do {
for (; end != haystack.end() && *end != split; ++end);
- exploded.push_back(string(start, end));
+ exploded.emplace_back(start, end);
start = end + 1;
} while (end != haystack.end() && (++end) != haystack.end());
return exploded;
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index 395227f50..0f1d407b7 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -266,12 +266,12 @@ bool pkgDPkgPM::Configure(PkgIterator Pkg)
if (Pkg.end() == true)
return false;
- List.push_back(Item(Item::Configure, Pkg));
+ List.emplace_back(Item::Configure, Pkg);
// Use triggers for config calls if we configure "smart"
// as otherwise Pre-Depends will not be satisfied, see #526774
if (_config->FindB("DPkg::TriggersPending", false) == true)
- List.push_back(Item(Item::TriggersPending, PkgIterator()));
+ List.emplace_back(Item::TriggersPending, PkgIterator());
return true;
}
@@ -285,9 +285,9 @@ bool pkgDPkgPM::Remove(PkgIterator Pkg,bool Purge)
return false;
if (Purge == true)
- List.push_back(Item(Item::Purge,Pkg));
+ List.emplace_back(Item::Purge,Pkg);
else
- List.push_back(Item(Item::Remove,Pkg));
+ List.emplace_back(Item::Remove,Pkg);
return true;
}
/*}}}*/
@@ -2328,10 +2328,10 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
// do not report dpkg I/O errors, this is a format string, so we compare
// the prefix and the suffix of the error with the dpkg error message
vector<string> io_errors;
- io_errors.push_back(string("failed to read"));
- io_errors.push_back(string("failed to write"));
- io_errors.push_back(string("failed to seek"));
- io_errors.push_back(string("unexpected end of file or stream"));
+ io_errors.emplace_back("failed to read");
+ io_errors.emplace_back("failed to write");
+ io_errors.emplace_back("failed to seek");
+ io_errors.emplace_back("unexpected end of file or stream");
for (vector<string>::iterator I = io_errors.begin(); I != io_errors.end(); ++I)
{
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc
index bfc187ea6..06132995b 100644
--- a/apt-pkg/solver3.cc
+++ b/apt-pkg/solver3.cc
@@ -949,7 +949,7 @@ void DependencySolver::Discover(Var var)
{
Clause clause{Var(Pkg), Group::SelectVersion};
for (auto ver = Pkg.VersionList(); not ver.end(); ver++)
- clause.solutions.push_back(Var(ver));
+ clause.solutions.emplace_back(ver);
std::stable_sort(clause.solutions.begin(), clause.solutions.end(), CompareProviders3{cache, policy, Pkg, *this});
RegisterClause(std::move(clause));
@@ -1067,7 +1067,7 @@ Clause DependencySolver::TranslateOrGroup(pkgCache::DepIterator start, pkgCache:
if (DeferVersionSelection && not start.IsNegative() && start.TargetPkg().ProvidesList().end() && start.IsSatisfied(start.TargetPkg()))
{
- clause.solutions.push_back(Var(start.TargetPkg()));
+ clause.solutions.emplace_back(start.TargetPkg());
}
else
{
@@ -1079,7 +1079,7 @@ Clause DependencySolver::TranslateOrGroup(pkgCache::DepIterator start, pkgCache:
if (unlikely(debug >= 3))
std::cerr << "Adding work to item " << reason.toString(cache) << " -> " << tgti.ParentPkg().FullName() << "=" << tgti.VerStr() << (clause.negative ? " (negative)" : "") << "\n";
- clause.solutions.push_back(Var(pkgCache::VerIterator(cache, *tgt)));
+ clause.solutions.emplace_back(pkgCache::VerIterator(cache, *tgt));
}
std::stable_sort(clause.solutions.begin() + begin, clause.solutions.end(), CompareProviders3{cache, policy, start.TargetPkg(), *this});
}
@@ -1259,13 +1259,13 @@ bool DependencySolver::FromDepCache(pkgDepCache &depcache)
else
{
Clause w{Var(), Group, isOptional};
- w.solutions.push_back(Var(P));
+ w.solutions.emplace_back(P);
auto insertedW = RegisterClause(std::move(w));
if (insertedW && not AddWork(Work{insertedW, decisionLevel()}))
return false;
if (not isAuto)
- manualPackages.push_back(Var(P));
+ manualPackages.emplace_back(P);
// Given A->A2|A1, B->B1|B2; Bn->An, if we select `not A1`, we
// should try to install A2 before trying B so we end up with
@@ -1274,7 +1274,7 @@ bool DependencySolver::FromDepCache(pkgDepCache &depcache)
// Compare test-bug-712116-dpkg-pre-install-pkgs-hook-multiarch
Clause shortcircuit{Var(), Group, isOptional};
for (auto V = P.VersionList(); not V.end(); ++V)
- shortcircuit.solutions.push_back(Var(V));
+ shortcircuit.solutions.emplace_back(V);
std::stable_sort(shortcircuit.solutions.begin(), shortcircuit.solutions.end(), CompareProviders3{cache, policy, P, *this});
auto insertedShort = RegisterClause(std::move(shortcircuit));
if (insertedShort && not AddWork(Work{insertedShort, decisionLevel()}))
@@ -1291,7 +1291,7 @@ bool DependencySolver::FromDepCache(pkgDepCache &depcache)
auto G = P.Group();
for (auto P = G.PackageList(); not P.end(); P = G.NextPkg(P))
if (P->Flags & pkgCache::Flag::Essential)
- w.solutions.push_back(Var(P));
+ w.solutions.emplace_back(P);
std::stable_sort(w.solutions.begin(), w.solutions.end(), CompareProviders3{cache, policy, P, *this});
if (unlikely(debug >= 1))
std::cerr << "Install essential package " << P << std::endl;
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 33c529712..7b3e6eee2 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -860,10 +860,10 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg
Cache->MarkAndSweep();
std::list<APT::VersionSet::Modifier> mods;
- mods.push_back(APT::VersionSet::Modifier(MOD_INSTALL, "+",
- APT::VersionSet::Modifier::POSTFIX, APT::CacheSetHelper::CANDIDATE));
- mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-",
- APT::VersionSet::Modifier::POSTFIX, APT::CacheSetHelper::NEWEST));
+ mods.emplace_back(MOD_INSTALL, "+",
+ APT::VersionSet::Modifier::POSTFIX, APT::CacheSetHelper::CANDIDATE);
+ mods.emplace_back(MOD_REMOVE, "-",
+ APT::VersionSet::Modifier::POSTFIX, APT::CacheSetHelper::NEWEST);
CacheSetHelperAPTGet helper(c0out);
verset = APT::VersionVector::GroupedFromCommandLine(Cache,
CmdL.FileList + 1, mods, fallback, helper);
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc
index d8e9e7e4b..ce2d79102 100644
--- a/cmdline/apt-cache.cc
+++ b/cmdline/apt-cache.cc
@@ -586,8 +586,8 @@ static bool XVcg(CommandLine &CmdL)
// Load the list of packages from the command line into the show list
APT::CacheSetHelper helper(true, GlobalError::NOTICE);
std::list<APT::CacheSetHelper::PkgModifier> mods;
- mods.push_back(APT::CacheSetHelper::PkgModifier(0, ",", APT::CacheSetHelper::PkgModifier::POSTFIX));
- mods.push_back(APT::CacheSetHelper::PkgModifier(1, "^", APT::CacheSetHelper::PkgModifier::POSTFIX));
+ mods.emplace_back(0, ",", APT::CacheSetHelper::PkgModifier::POSTFIX);
+ mods.emplace_back(1, "^", APT::CacheSetHelper::PkgModifier::POSTFIX);
std::map<unsigned short, APT::PackageSet> pkgsets =
APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper);
@@ -799,8 +799,8 @@ static bool Dotty(CommandLine &CmdL)
// Load the list of packages from the command line into the show list
APT::CacheSetHelper helper(true, GlobalError::NOTICE);
std::list<APT::CacheSetHelper::PkgModifier> mods;
- mods.push_back(APT::CacheSetHelper::PkgModifier(0, ",", APT::CacheSetHelper::PkgModifier::POSTFIX));
- mods.push_back(APT::CacheSetHelper::PkgModifier(1, "^", APT::CacheSetHelper::PkgModifier::POSTFIX));
+ mods.emplace_back(0, ",", APT::CacheSetHelper::PkgModifier::POSTFIX);
+ mods.emplace_back(1, "^", APT::CacheSetHelper::PkgModifier::POSTFIX);
std::map<unsigned short, APT::PackageSet> pkgsets =
APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper);
diff --git a/methods/rred.cc b/methods/rred.cc
index 836697a11..56b536a82 100644
--- a/methods/rred.cc
+++ b/methods/rred.cc
@@ -657,7 +657,7 @@ class RredMethod final : public aptMethod {
std::string const FileName = Path + ".ed";
if (ExpectedHashes.usable() == false)
return _error->Error("No hashes found for uncompressed patch: %s", FileName.c_str());
- patchfiles.push_back(PDiffFile(FileName, ExpectedHashes));
+ patchfiles.emplace_back(FileName, ExpectedHashes);
}
else
{
@@ -675,7 +675,7 @@ class RredMethod final : public aptMethod {
HashStringList const ExpectedHashes = ReadExpectedHashesForPatch(seen_patches, Message);
if (ExpectedHashes.usable() == false)
return _error->Error("No hashes found for uncompressed patch %d: %s", seen_patches, p->c_str());
- patchfiles.push_back(PDiffFile(*p, ExpectedHashes));
+ patchfiles.emplace_back(*p, ExpectedHashes);
++seen_patches;
}
}