summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-11-05 04:52:50 +0800
committerRich Trott <rtrott@gmail.com>2018-11-07 20:40:38 -0800
commitf895b5a58ec930d3ca49ebf34959a598c7669d77 (patch)
tree3ce1f6bcb6247fa6ecad1479c0d01e56d2f1074d /src
parent350bef6a103593f824e6a43ff52a86f1a48267db (diff)
downloadandroid-node-v8-f895b5a58ec930d3ca49ebf34959a598c7669d77.tar.gz
android-node-v8-f895b5a58ec930d3ca49ebf34959a598c7669d77.tar.bz2
android-node-v8-f895b5a58ec930d3ca49ebf34959a598c7669d77.zip
src: cache the result of GetOptions() in JS land
Instead of calling into C++ each time we need to check the value of a command line option, cache the option map in a new `internal/options` module for faster access to the values in JS land. PR-URL: https://github.com/nodejs/node/pull/24091 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_options.cc17
1 files changed, 2 insertions, 15 deletions
diff --git a/src/node_options.cc b/src/node_options.cc
index 4951679994..98beb9f4c6 100644
--- a/src/node_options.cc
+++ b/src/node_options.cc
@@ -365,9 +365,8 @@ HostPort SplitHostPort(const std::string& arg,
ParseAndValidatePort(arg.substr(colon + 1), errors) };
}
-// Usage: Either:
-// - getOptions() to get all options + metadata or
-// - getOptions(string) to get the value of a particular option
+// Return a map containing all the options and their metadata as well
+// as the aliases
void GetOptions(const FunctionCallbackInfo<Value>& args) {
Mutex::ScopedLock lock(per_process_opts_mutex);
Environment* env = Environment::GetCurrent(args);
@@ -388,13 +387,8 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) {
const auto& parser = PerProcessOptionsParser::instance;
- std::string filter;
- if (args[0]->IsString()) filter = *node::Utf8Value(isolate, args[0]);
-
Local<Map> options = Map::New(isolate);
for (const auto& item : parser.options_) {
- if (!filter.empty() && item.first != filter) continue;
-
Local<Value> value;
const auto& option_info = item.second;
auto field = option_info.field;
@@ -443,11 +437,6 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) {
}
CHECK(!value.IsEmpty());
- if (!filter.empty()) {
- args.GetReturnValue().Set(value);
- return;
- }
-
Local<Value> name = ToV8Value(context, item.first).ToLocalChecked();
Local<Object> info = Object::New(isolate);
Local<Value> help_text;
@@ -469,8 +458,6 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) {
}
}
- if (!filter.empty()) return;
-
Local<Value> aliases;
if (!ToV8Value(context, parser.aliases_).ToLocal(&aliases)) return;