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:
parent
689ef502f5
commit
43677021e3
60 changed files with 189 additions and 166 deletions
2
third_party/nix/src/libutil/archive.cc
vendored
2
third_party/nix/src/libutil/archive.cc
vendored
|
|
@ -145,7 +145,7 @@ void dumpString(const std::string& s, Sink& sink) {
|
|||
<< "contents" << s << ")";
|
||||
}
|
||||
|
||||
static SerialisationError badArchive(string s) {
|
||||
static SerialisationError badArchive(const string& s) {
|
||||
return SerialisationError("bad archive: " + s);
|
||||
}
|
||||
|
||||
|
|
|
|||
2
third_party/nix/src/libutil/args.cc
vendored
2
third_party/nix/src/libutil/args.cc
vendored
|
|
@ -175,7 +175,7 @@ Args::FlagMaker& Args::FlagMaker::mkHashTypeFlag(HashType* ht) {
|
|||
arity(1);
|
||||
label("type");
|
||||
description("hash algorithm ('md5', 'sha1', 'sha256', or 'sha512')");
|
||||
handler([ht](std::string s) {
|
||||
handler([ht](const std::string& s) {
|
||||
*ht = parseHashType(s);
|
||||
if (*ht == htUnknown) {
|
||||
throw UsageError("unknown hash type '%1%'", s);
|
||||
|
|
|
|||
4
third_party/nix/src/libutil/config.cc
vendored
4
third_party/nix/src/libutil/config.cc
vendored
|
|
@ -246,12 +246,12 @@ void BaseSetting<bool>::convertToArg(Args& args, const std::string& category) {
|
|||
args.mkFlag()
|
||||
.longName(name)
|
||||
.description(description)
|
||||
.handler([=](std::vector<std::string> ss) { override(true); })
|
||||
.handler([=](const std::vector<std::string>& ss) { override(true); })
|
||||
.category(category);
|
||||
args.mkFlag()
|
||||
.longName("no-" + name)
|
||||
.description(description)
|
||||
.handler([=](std::vector<std::string> ss) { override(false); })
|
||||
.handler([=](const std::vector<std::string>& ss) { override(false); })
|
||||
.category(category);
|
||||
}
|
||||
|
||||
|
|
|
|||
4
third_party/nix/src/libutil/serialise.cc
vendored
4
third_party/nix/src/libutil/serialise.cc
vendored
|
|
@ -157,8 +157,8 @@ size_t StringSource::read(unsigned char* data, size_t len) {
|
|||
#error Coroutines are broken in this version of Boost!
|
||||
#endif
|
||||
|
||||
std::unique_ptr<Source> sinkToSource(std::function<void(Sink&)> fun,
|
||||
std::function<void()> eof) {
|
||||
std::unique_ptr<Source> sinkToSource(const std::function<void(Sink&)>& fun,
|
||||
const std::function<void()>& eof) {
|
||||
struct SinkToSource : Source {
|
||||
using coro_t = boost::coroutines2::coroutine<std::string>;
|
||||
|
||||
|
|
|
|||
3
third_party/nix/src/libutil/serialise.hh
vendored
3
third_party/nix/src/libutil/serialise.hh
vendored
|
|
@ -209,7 +209,8 @@ struct LambdaSource : Source {
|
|||
/* Convert a function that feeds data into a Sink into a Source. The
|
||||
Source executes the function as a coroutine. */
|
||||
std::unique_ptr<Source> sinkToSource(
|
||||
std::function<void(Sink&)> fun, std::function<void()> eof = []() {
|
||||
const std::function<void(Sink&)>& fun,
|
||||
const std::function<void()>& eof = []() {
|
||||
throw EndOfFile("coroutine has finished");
|
||||
});
|
||||
|
||||
|
|
|
|||
14
third_party/nix/src/libutil/util.cc
vendored
14
third_party/nix/src/libutil/util.cc
vendored
|
|
@ -76,9 +76,9 @@ void clearEnv() {
|
|||
}
|
||||
}
|
||||
|
||||
void replaceEnv(std::map<std::string, std::string> newEnv) {
|
||||
void replaceEnv(const std::map<std::string, std::string>& newEnv) {
|
||||
clearEnv();
|
||||
for (auto newEnvVar : newEnv) {
|
||||
for (const auto& newEnvVar : newEnv) {
|
||||
setenv(newEnvVar.first.c_str(), newEnvVar.second.c_str(), 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -888,9 +888,9 @@ void killUser(uid_t uid) {
|
|||
|
||||
/* Wrapper around vfork to prevent the child process from clobbering
|
||||
the caller's stack frame in the parent. */
|
||||
static pid_t doFork(bool allowVfork, std::function<void()> fun)
|
||||
static pid_t doFork(bool allowVfork, const std::function<void()>& fun)
|
||||
__attribute__((noinline));
|
||||
static pid_t doFork(bool allowVfork, std::function<void()> fun) {
|
||||
static pid_t doFork(bool allowVfork, const std::function<void()>& fun) {
|
||||
#ifdef __linux__
|
||||
pid_t pid = allowVfork ? vfork() : fork();
|
||||
#else
|
||||
|
|
@ -944,7 +944,7 @@ std::vector<char*> stringsToCharPtrs(const Strings& ss) {
|
|||
return res;
|
||||
}
|
||||
|
||||
string runProgram(Path program, bool searchPath, const Strings& args,
|
||||
string runProgram(const Path& program, bool searchPath, const Strings& args,
|
||||
const std::optional<std::string>& input) {
|
||||
RunOptions opts(program, args);
|
||||
opts.searchPath = searchPath;
|
||||
|
|
@ -1425,7 +1425,7 @@ string base64Decode(const string& s) {
|
|||
}
|
||||
|
||||
void callFailure(const std::function<void(std::exception_ptr exc)>& failure,
|
||||
std::exception_ptr exc) {
|
||||
const std::exception_ptr& exc) {
|
||||
try {
|
||||
failure(exc);
|
||||
} catch (std::exception& e) {
|
||||
|
|
@ -1516,7 +1516,7 @@ struct InterruptCallbackImpl : InterruptCallback {
|
|||
};
|
||||
|
||||
std::unique_ptr<InterruptCallback> createInterruptCallback(
|
||||
std::function<void()> callback) {
|
||||
const std::function<void()>& callback) {
|
||||
auto interruptCallbacks(_interruptCallbacks.lock());
|
||||
interruptCallbacks->push_back(callback);
|
||||
|
||||
|
|
|
|||
4
third_party/nix/src/libutil/util.hh
vendored
4
third_party/nix/src/libutil/util.hh
vendored
|
|
@ -246,7 +246,7 @@ pid_t startProcess(std::function<void()> fun,
|
|||
|
||||
/* Run a program and return its stdout in a string (i.e., like the
|
||||
shell backtick operator). */
|
||||
string runProgram(Path program, bool searchPath = false,
|
||||
string runProgram(const Path& program, bool searchPath = false,
|
||||
const Strings& args = Strings(),
|
||||
const std::optional<std::string>& input = {});
|
||||
|
||||
|
|
@ -453,7 +453,7 @@ struct InterruptCallback {
|
|||
/* Register a function that gets called on SIGINT (in a non-signal
|
||||
context). */
|
||||
std::unique_ptr<InterruptCallback> createInterruptCallback(
|
||||
std::function<void()> callback);
|
||||
const std::function<void()>& callback);
|
||||
|
||||
void triggerInterrupt();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue