Make BuildHandlerArgvStrings() return its result

This is more direct than using an out-parameter. Copy elision should
make it equally performant, and even in the absence of copy elision,
this would now be an inexpensive move operation.

Change-Id: Iaf0eb07b36c8e35ff8942fc422a22321bf5c3010
Reviewed-on: https://chromium-review.googlesource.com/1145495
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Mark Mentovai 2018-07-20 15:56:49 -04:00
parent 98ebb0060b
commit e50ea60321
5 changed files with 19 additions and 30 deletions

View File

@ -1 +0,0 @@
This is a whitespace file used to kick off jobs.

View File

@ -27,38 +27,38 @@ std::string FormatArgumentString(const std::string& name,
} // namespace
void BuildHandlerArgvStrings(
std::vector<std::string> BuildHandlerArgvStrings(
const base::FilePath& handler,
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
std::vector<std::string>* argv_strings) {
argv_strings->clear();
const std::vector<std::string>& arguments) {
std::vector<std::string> argv_strings(1, handler.value());
argv_strings->push_back(handler.value());
for (const auto& argument : arguments) {
argv_strings->push_back(argument);
argv_strings.push_back(argument);
}
if (!database.empty()) {
argv_strings->push_back(FormatArgumentString("database", database.value()));
argv_strings.push_back(FormatArgumentString("database", database.value()));
}
if (!metrics_dir.empty()) {
argv_strings->push_back(
argv_strings.push_back(
FormatArgumentString("metrics-dir", metrics_dir.value()));
}
if (!url.empty()) {
argv_strings->push_back(FormatArgumentString("url", url));
argv_strings.push_back(FormatArgumentString("url", url));
}
for (const auto& kv : annotations) {
argv_strings->push_back(
argv_strings.push_back(
FormatArgumentString("annotation", kv.first + '=' + kv.second));
}
return argv_strings;
}
void ConvertArgvStrings(const std::vector<std::string>& argv_strings,

View File

@ -28,16 +28,14 @@ namespace crashpad {
//!
//! See StartHandlerAtCrash() for documentation on the input arguments.
//!
//! \param[out] A argv_strings vector of arguments suitable for starting the
//! handler with.
void BuildHandlerArgvStrings(
//! \return A vector of arguments suitable for starting the handler with.
std::vector<std::string> BuildHandlerArgvStrings(
const base::FilePath& handler,
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
std::vector<std::string>* argv_strings);
const std::vector<std::string>& arguments);
//! \brief Flattens a string vector into a const char* vector suitable for use
//! in an exec() call.

View File

@ -58,14 +58,8 @@ bool CrashpadClient::StartHandler(
return false;
}
std::vector<std::string> argv_strings;
BuildHandlerArgvStrings(handler,
database,
metrics_dir,
url,
annotations,
arguments,
&argv_strings);
std::vector<std::string> argv_strings = BuildHandlerArgvStrings(
handler, database, metrics_dir, url, annotations, arguments);
std::vector<const char*> argv;
ConvertArgvStrings(argv_strings, &argv);

View File

@ -175,9 +175,8 @@ bool CrashpadClient::StartHandlerAtCrash(
const std::string& url,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments) {
std::vector<std::string> argv;
BuildHandlerArgvStrings(
handler, database, metrics_dir, url, annotations, arguments, &argv);
std::vector<std::string> argv = BuildHandlerArgvStrings(
handler, database, metrics_dir, url, annotations, arguments);
auto signal_handler = LaunchAtCrashHandler::Get();
if (signal_handler->Initialize(&argv)) {
@ -197,9 +196,8 @@ bool CrashpadClient::StartHandlerForClient(
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
int socket) {
std::vector<std::string> argv;
BuildHandlerArgvStrings(
handler, database, metrics_dir, url, annotations, arguments, &argv);
std::vector<std::string> argv = BuildHandlerArgvStrings(
handler, database, metrics_dir, url, annotations, arguments);
argv.push_back(FormatArgumentInt("initial-client", socket));