refactor(3p/nix): Apply clang-tidy's performance-* fixes

This applies the performance fixes listed here:

https://clang.llvm.org/extra/clang-tidy/checks/list.html
This commit is contained in:
Vincent Ambo 2020-05-20 22:58:43 +01:00
parent 689ef502f5
commit 43677021e3
60 changed files with 189 additions and 166 deletions

View file

@ -29,7 +29,7 @@ MixEvalArgs::MixEvalArgs() {
"add a path to the list of locations used to look up <...> file "
"names")
.label("path")
.handler([&](std::string s) { searchPath.push_back(s); });
.handler([&](const std::string& s) { searchPath.push_back(s); });
}
Bindings* MixEvalArgs::getAutoArgs(EvalState& state) {

View file

@ -298,7 +298,7 @@ static Strings parseNixPath(const string& s) {
return res;
}
EvalState::EvalState(const Strings& _searchPath, ref<Store> store)
EvalState::EvalState(const Strings& _searchPath, const ref<Store>& store)
: sWith(symbols.create("<with>")),
sOutPath(symbols.create("outPath")),
sDrvPath(symbols.create("drvPath")),

View file

@ -105,7 +105,7 @@ class EvalState {
std::unordered_map<Path, Path> resolvedPaths;
public:
EvalState(const Strings& _searchPath, ref<Store> store);
EvalState(const Strings& _searchPath, const ref<Store>& store);
~EvalState();
void addToSearchPath(const string& s);

View file

@ -15,7 +15,7 @@ namespace nix {
DrvInfo::DrvInfo(EvalState& state, string attrPath, Bindings* attrs)
: state(&state), attrs(attrs), attrPath(std::move(attrPath)) {}
DrvInfo::DrvInfo(EvalState& state, ref<Store> store,
DrvInfo::DrvInfo(EvalState& state, const ref<Store>& store,
const std::string& drvPathWithOutputs)
: state(&state), attrPath("") {
auto spec = parseDrvPathWithOutputs(drvPathWithOutputs);

View file

@ -34,7 +34,7 @@ struct DrvInfo {
DrvInfo(EvalState& state) : state(&state){};
DrvInfo(EvalState& state, string attrPath, Bindings* attrs);
DrvInfo(EvalState& state, ref<Store> store,
DrvInfo(EvalState& state, const ref<Store>& store,
const std::string& drvPathWithOutputs);
string queryName() const;

View file

@ -34,7 +34,7 @@ namespace nix {
name>. */
std::pair<string, string> decodeContext(const string& s) {
if (s.at(0) == '!') {
size_t index = s.find("!", 1);
size_t index = s.find('!', 1);
return std::pair<string, string>(string(s, index + 1),
string(s, 1, index - 1));
}
@ -2172,7 +2172,7 @@ static void prim_splitVersion(EvalState& state, const Pos& pos, Value** args,
unsigned int n = 0;
for (auto& component : components) {
auto listElem = v.listElems()[n++] = state.allocValue();
mkString(*listElem, std::move(component));
mkString(*listElem, component);
}
}
@ -2246,7 +2246,8 @@ static void prim_fetchTarball(EvalState& state, const Pos& pos, Value** args,
RegisterPrimOp::PrimOps* RegisterPrimOp::primOps;
RegisterPrimOp::RegisterPrimOp(std::string name, size_t arity, PrimOpFun fun) {
RegisterPrimOp::RegisterPrimOp(const std::string& name, size_t arity,
PrimOpFun fun) {
if (primOps == nullptr) {
primOps = new PrimOps;
}

View file

@ -11,7 +11,7 @@ struct RegisterPrimOp {
/* You can register a constant by passing an arity of 0. fun
will get called during EvalState initialization, so there
may be primops not yet added and builtins is not yet sorted. */
RegisterPrimOp(std::string name, size_t arity, PrimOpFun fun);
RegisterPrimOp(const std::string& name, size_t arity, PrimOpFun fun);
};
/* These primops are disabled without enableNativeCode, but plugins