Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a6fe2ca

Browse filesBrowse files
addaleaxtargos
authored andcommitted
src: simplify TimerFunctionCall() in node_perf.cc
Picking a path according to a boolean is essentially free, compared to the cost of a function call. Also, remove an unnecessary `TryCatch`. PR-URL: #23782 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 30be5cb commit a6fe2ca
Copy full SHA for a6fe2ca

File tree

Expand file treeCollapse file tree

1 file changed

+20
-39
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-39
lines changed
Open diff view settings
Collapse file

‎src/node_perf.cc‎

Copy file name to clipboardExpand all lines: src/node_perf.cc
+20-39Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -317,49 +317,30 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
317317
size_t idx;
318318
SlicedArguments call_args(args);
319319
Utf8Value name(isolate, GetName(fn));
320+
bool is_construct_call = args.IsConstructCall();
320321

321-
uint64_t start;
322-
uint64_t end;
323-
v8::TryCatch try_catch(isolate);
324-
if (args.IsConstructCall()) {
325-
start = PERFORMANCE_NOW();
326-
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
327-
TRACING_CATEGORY_NODE2(perf, timerify),
328-
*name, *name, start / 1000);
329-
v8::MaybeLocal<Object> ret = fn->NewInstance(context,
330-
call_args.size(),
331-
call_args.data());
332-
end = PERFORMANCE_NOW();
333-
TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
334-
TRACING_CATEGORY_NODE2(perf, timerify),
335-
*name, *name, end / 1000);
336-
337-
if (ret.IsEmpty()) {
338-
try_catch.ReThrow();
339-
return;
340-
}
341-
args.GetReturnValue().Set(ret.ToLocalChecked());
322+
uint64_t start = PERFORMANCE_NOW();
323+
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
324+
TRACING_CATEGORY_NODE2(perf, timerify),
325+
*name, *name, start / 1000);
326+
v8::MaybeLocal<Value> ret;
327+
328+
if (is_construct_call) {
329+
ret = fn->NewInstance(context, call_args.size(), call_args.data())
330+
.FromMaybe(Local<Object>());
342331
} else {
343-
start = PERFORMANCE_NOW();
344-
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
345-
TRACING_CATEGORY_NODE2(perf, timerify),
346-
*name, *name, start / 1000);
347-
v8::MaybeLocal<Value> ret = fn->Call(context,
348-
args.This(),
349-
call_args.size(),
350-
call_args.data());
351-
end = PERFORMANCE_NOW();
352-
TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
353-
TRACING_CATEGORY_NODE2(perf, timerify),
354-
*name, *name, end / 1000);
355-
356-
if (ret.IsEmpty()) {
357-
try_catch.ReThrow();
358-
return;
359-
}
360-
args.GetReturnValue().Set(ret.ToLocalChecked());
332+
ret = fn->Call(context, args.This(), call_args.size(), call_args.data());
361333
}
362334

335+
uint64_t end = PERFORMANCE_NOW();
336+
TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
337+
TRACING_CATEGORY_NODE2(perf, timerify),
338+
*name, *name, end / 1000);
339+
340+
if (ret.IsEmpty())
341+
return;
342+
args.GetReturnValue().Set(ret.ToLocalChecked());
343+
363344
AliasedBuffer<uint32_t, v8::Uint32Array>& observers =
364345
env->performance_state()->observers;
365346
if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.