Skip to content

Commit

Permalink
Merge pull request NixOS#11847 from xokdvium/dev/some-vector-reserves
Browse files Browse the repository at this point in the history
refactor(treewide): reserve vector capacity when final size is known
  • Loading branch information
Mic92 authored Nov 9, 2024
2 parents 6e55f2c + 0fe3b54 commit cdcf9bd
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/libstore/build/entry-points.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/libstore/path-with-outputs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/libutil/executable-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/nix/develop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit cdcf9bd

Please sign in to comment.