From f213a055f6c666d09dc7ef64e4edeccab3cfea62 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 15 Dec 2018 21:13:44 +0100 Subject: [PATCH] src: mark options parsers as const These do not change their contents after being constructed. PR-URL: https://github.com/nodejs/node/pull/25065 Reviewed-By: Colin Ihrig Reviewed-By: Joyee Cheung Reviewed-By: James M Snell --- src/node_options-inl.h | 4 ++-- src/node_options.cc | 8 ++++---- src/node_options.h | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index cfa3cdc9bbe33d..f482bcd36660ed 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -214,7 +214,7 @@ auto OptionsParser::Convert( template template void OptionsParser::Insert( - OptionsParser* child_options_parser, + const OptionsParser* child_options_parser, ChildOptions* (Options::* get_child)()) { aliases_.insert(child_options_parser->aliases_.begin(), child_options_parser->aliases_.end()); @@ -287,7 +287,7 @@ void OptionsParser::Parse( std::vector* const v8_args, Options* const options, OptionEnvvarSettings required_env_settings, - std::vector* const errors) { + std::vector* const errors) const { ArgsInfo args(orig_args, exec_args); // The first entry is the process name. Make sure it ends up in the V8 argv, diff --git a/src/node_options.cc b/src/node_options.cc index 72e9ad86b76ee4..1d3a1691fa0845 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -88,7 +88,7 @@ DebugOptionsParser::DebugOptionsParser() { } #if HAVE_INSPECTOR -DebugOptionsParser DebugOptionsParser::instance; +const DebugOptionsParser DebugOptionsParser::instance; #endif // HAVE_INSPECTOR EnvironmentOptionsParser::EnvironmentOptionsParser() { @@ -211,7 +211,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { #endif // HAVE_INSPECTOR } -EnvironmentOptionsParser EnvironmentOptionsParser::instance; +const EnvironmentOptionsParser EnvironmentOptionsParser::instance; PerIsolateOptionsParser::PerIsolateOptionsParser() { AddOption("--track-heap-objects", @@ -234,7 +234,7 @@ PerIsolateOptionsParser::PerIsolateOptionsParser() { &PerIsolateOptions::get_per_env_options); } -PerIsolateOptionsParser PerIsolateOptionsParser::instance; +const PerIsolateOptionsParser PerIsolateOptionsParser::instance; PerProcessOptionsParser::PerProcessOptionsParser() { AddOption("--title", @@ -342,7 +342,7 @@ PerProcessOptionsParser::PerProcessOptionsParser() { &PerProcessOptions::get_per_isolate_options); } -PerProcessOptionsParser PerProcessOptionsParser::instance; +const PerProcessOptionsParser PerProcessOptionsParser::instance; inline std::string RemoveBrackets(const std::string& host) { if (!host.empty() && host.front() == '[' && host.back() == ']') diff --git a/src/node_options.h b/src/node_options.h index 4bfc49df1172a1..40eae6f7f8f358 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -281,7 +281,7 @@ class OptionsParser { // a method that yields the target options type from this parser's options // type. template - void Insert(OptionsParser* child_options_parser, + void Insert(const OptionsParser* child_options_parser, ChildOptions* (Options::* get_child)()); // Parse a sequence of options into an options struct, a list of @@ -306,7 +306,7 @@ class OptionsParser { std::vector* const v8_args, Options* const options, OptionEnvvarSettings required_env_settings, - std::vector* const errors); + std::vector* const errors) const; private: // We support the wide variety of different option types by remembering @@ -397,28 +397,28 @@ class DebugOptionsParser : public OptionsParser { public: DebugOptionsParser(); - static DebugOptionsParser instance; + static const DebugOptionsParser instance; }; class EnvironmentOptionsParser : public OptionsParser { public: EnvironmentOptionsParser(); - static EnvironmentOptionsParser instance; + static const EnvironmentOptionsParser instance; }; class PerIsolateOptionsParser : public OptionsParser { public: PerIsolateOptionsParser(); - static PerIsolateOptionsParser instance; + static const PerIsolateOptionsParser instance; }; class PerProcessOptionsParser : public OptionsParser { public: PerProcessOptionsParser(); - static PerProcessOptionsParser instance; + static const PerProcessOptionsParser instance; }; } // namespace options_parser