mirror of
https://github.com/NixOS/nix.git
synced 2024-11-25 00:02:25 +00:00
refactor(treewide): reserve vector capacity when final size is known
In these trivial cases the final vector size (or lower bound on the size) is known, so we can avoid some vector reallocations. This is not very important, but is just good practice and general hygiene.
This commit is contained in:
parent
492c678162
commit
0fe3b54ee1
@ -857,6 +857,7 @@ std::vector<FlakeRef> RawInstallablesCommand::getFlakeRefsForCompletion()
|
||||
{
|
||||
applyDefaultInstallables(rawInstallables);
|
||||
std::vector<FlakeRef> res;
|
||||
res.reserve(rawInstallables.size());
|
||||
for (auto i : rawInstallables)
|
||||
res.push_back(parseFlakeRefWithFragment(
|
||||
fetchSettings,
|
||||
|
@ -91,6 +91,7 @@ StringMap EvalState::realiseContext(const NixStringContext & context, StorePathS
|
||||
|
||||
/* Build/substitute the context. */
|
||||
std::vector<DerivedPath> buildReqs;
|
||||
buildReqs.reserve(drvs.size());
|
||||
for (auto & d : drvs) buildReqs.emplace_back(DerivedPath { d });
|
||||
buildStore->buildPaths(buildReqs, bmNormal, store);
|
||||
|
||||
|
@ -66,6 +66,7 @@ std::vector<KeyedBuildResult> Store::buildPathsWithResults(
|
||||
worker.run(goals);
|
||||
|
||||
std::vector<KeyedBuildResult> results;
|
||||
results.reserve(state.size());
|
||||
|
||||
for (auto & [req, goalPtr] : state)
|
||||
results.emplace_back(KeyedBuildResult {
|
||||
|
@ -37,6 +37,7 @@ DerivedPath StorePathWithOutputs::toDerivedPath() const
|
||||
std::vector<DerivedPath> toDerivedPaths(const std::vector<StorePathWithOutputs> ss)
|
||||
{
|
||||
std::vector<DerivedPath> reqs;
|
||||
reqs.reserve(ss.size());
|
||||
for (auto & s : ss) reqs.push_back(s.toDerivedPath());
|
||||
return reqs;
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ ExecutablePath ExecutablePath::parse(const OsString & path)
|
||||
OsString ExecutablePath::render() const
|
||||
{
|
||||
std::vector<PathViewNG> path2;
|
||||
path2.reserve(directories.size());
|
||||
for (auto & p : directories)
|
||||
path2.push_back(p.native());
|
||||
return basicConcatStringsSep(path_var_separator, path2);
|
||||
|
@ -610,6 +610,7 @@ struct CmdDevelop : Common, MixEnvironment
|
||||
|
||||
else if (!command.empty()) {
|
||||
std::vector<std::string> args;
|
||||
args.reserve(command.size());
|
||||
for (auto s : command)
|
||||
args.push_back(shellEscape(s));
|
||||
script += fmt("exec %s\n", concatStringsSep(" ", args));
|
||||
|
Loading…
Reference in New Issue
Block a user