init: Simplify struct BuiltinArguments

Make the code that creates BuiltinArguments instances easier to read by
using initializer lists instead of constructor calls. Remove the
BuiltinArguments constructors.

Change-Id: I6cf215a81d298cf7e524e22fb75db820e0225c9a
Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
Bart Van Assche 2023-02-22 10:01:33 -08:00
parent bae352bddb
commit 3dfb8bc889
4 changed files with 4 additions and 8 deletions

View file

@ -30,7 +30,7 @@ namespace init {
Result<void> RunBuiltinFunction(const BuiltinFunction& function,
const std::vector<std::string>& args, const std::string& context) {
auto builtin_arguments = BuiltinArguments(context);
BuiltinArguments builtin_arguments{.context = context};
builtin_arguments.args.resize(args.size());
builtin_arguments.args[0] = args[0];
@ -69,7 +69,7 @@ Result<void> Command::InvokeFunc(Subcontext* subcontext) const {
}
Result<void> Command::CheckCommand() const {
auto builtin_arguments = BuiltinArguments("host_init_verifier");
BuiltinArguments builtin_arguments{.context = "host_init_verifier"};
builtin_arguments.args.resize(args_.size());
builtin_arguments.args[0] = args_[0];

View file

@ -24,10 +24,6 @@ namespace android {
namespace init {
struct BuiltinArguments {
BuiltinArguments(const std::string& context) : context(context) {}
BuiltinArguments(std::vector<std::string> args, const std::string& context)
: args(std::move(args)), context(context) {}
const std::string& operator[](std::size_t i) const { return args[i]; }
auto begin() const { return args.begin(); }
auto end() const { return args.end(); }

View file

@ -1074,7 +1074,7 @@ static Result<void> do_restorecon(const BuiltinArguments& args) {
static Result<void> do_restorecon_recursive(const BuiltinArguments& args) {
std::vector<std::string> non_const_args(args.args);
non_const_args.insert(std::next(non_const_args.begin()), "--recursive");
return do_restorecon({std::move(non_const_args), args.context});
return do_restorecon({.args = std::move(non_const_args), .context = args.context});
}
static Result<void> do_loglevel(const BuiltinArguments& args) {

View file

@ -85,7 +85,7 @@ Result<void> check_exec_background(const BuiltinArguments& args) {
}
Result<void> check_exec_reboot_on_failure(const BuiltinArguments& args) {
BuiltinArguments remaining_args(args.context);
BuiltinArguments remaining_args{.context = args.context};
remaining_args.args = std::vector<std::string>(args.begin() + 1, args.end());
remaining_args.args[0] = args[0];