From c430aebe8683699fc072cb87e5be03af370a3f2f Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 30 Nov 2019 11:04:34 +0100 Subject: util: improve performance inspecting proxies This makes sure we do not retrieve the handler in case it's not required. This improves the performance a tiny bit for these cases. PR-URL: https://github.com/nodejs/node/pull/30767 Reviewed-By: James M Snell Reviewed-By: Denys Otrishko Reviewed-By: Rich Trott --- src/node_util.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/node_util.cc b/src/node_util.cc index 9c24985a47a..07a7b69dbd9 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -91,15 +91,23 @@ static void GetProxyDetails(const FunctionCallbackInfo& args) { if (!args[0]->IsProxy()) return; + CHECK(args[1]->IsBoolean()); + Local proxy = args[0].As(); - Local ret[] = { - proxy->GetTarget(), - proxy->GetHandler() - }; + if (args[1]->IsTrue()) { + Local ret[] = { + proxy->GetTarget(), + proxy->GetHandler() + }; - args.GetReturnValue().Set( - Array::New(args.GetIsolate(), ret, arraysize(ret))); + args.GetReturnValue().Set( + Array::New(args.GetIsolate(), ret, arraysize(ret))); + } else { + Local ret = proxy->GetTarget(); + + args.GetReturnValue().Set(ret); + } } static void PreviewEntries(const FunctionCallbackInfo& args) { -- cgit v1.2.3