Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns: avoid use of arguments #11359

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ function errnoException(err, syscall, hostname) {
// callback.immediately = true;
// }
function makeAsync(callback) {
return function asyncCallback() {
return function asyncCallback(...args) {
if (asyncCallback.immediately) {
// The API already returned, we can invoke the callback immediately.
callback.apply(null, arguments);
callback.apply(null, args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rewrite to callback(...args)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spread arguments still appear to be quite a bit slower according to benchmarks. Even the ...args has mixed results that I haven't quite been able to track down the cause of.

} else {
var args = new Array(arguments.length + 1);
args[0] = callback;
for (var i = 0; i < arguments.length; ++i)
args[i + 1] = arguments[i];
args.unshift(callback);
process.nextTick.apply(null, args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And process.nextTick(callback, ...args)

}
};
Expand Down