From 3dfb8bc8892e1e0d09e216751b93cc1cc1fb941c Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 22 Feb 2023 10:01:33 -0800 Subject: [PATCH] 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 --- init/action.cpp | 4 ++-- init/builtin_arguments.h | 4 ---- init/builtins.cpp | 2 +- init/check_builtins.cpp | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/init/action.cpp b/init/action.cpp index 1e998aeeb..18f636042 100644 --- a/init/action.cpp +++ b/init/action.cpp @@ -30,7 +30,7 @@ namespace init { Result RunBuiltinFunction(const BuiltinFunction& function, const std::vector& 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 Command::InvokeFunc(Subcontext* subcontext) const { } Result 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]; diff --git a/init/builtin_arguments.h b/init/builtin_arguments.h index 1742b78a6..890a21681 100644 --- a/init/builtin_arguments.h +++ b/init/builtin_arguments.h @@ -24,10 +24,6 @@ namespace android { namespace init { struct BuiltinArguments { - BuiltinArguments(const std::string& context) : context(context) {} - BuiltinArguments(std::vector 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(); } diff --git a/init/builtins.cpp b/init/builtins.cpp index a89813e44..bc23972a2 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -1074,7 +1074,7 @@ static Result do_restorecon(const BuiltinArguments& args) { static Result do_restorecon_recursive(const BuiltinArguments& args) { std::vector 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 do_loglevel(const BuiltinArguments& args) { diff --git a/init/check_builtins.cpp b/init/check_builtins.cpp index 481fa31e5..461ed2255 100644 --- a/init/check_builtins.cpp +++ b/init/check_builtins.cpp @@ -85,7 +85,7 @@ Result check_exec_background(const BuiltinArguments& args) { } Result check_exec_reboot_on_failure(const BuiltinArguments& args) { - BuiltinArguments remaining_args(args.context); + BuiltinArguments remaining_args{.context = args.context}; remaining_args.args = std::vector(args.begin() + 1, args.end()); remaining_args.args[0] = args[0];