Skip to content
Merged
Changes from 1 commit
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
Next Next commit
net: remove unnecessary variables
V8 is smart enough to optimize the length property checking when
iterating over an array with a for loop.

PR-URL: #8112
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
mscdex committed Aug 23, 2016
commit d28159f0fc488dd58ae64a03a91480870eed5390
10 changes: 4 additions & 6 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ exports.createServer = function(options, connectionListener) {
// connect(path, [cb]);
//
exports.connect = exports.createConnection = function() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps switch to function(...args) { here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I haven't ran the relevant benchmarks recently (at least with v8 5.1), but I wouldn't be surprised if rest args are still slower.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

They are still a bit slower.

const argsLen = arguments.length;
var args = new Array(argsLen);
for (var i = 0; i < argsLen; i++)
var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i++)
args[i] = arguments[i];
args = normalizeConnectArgs(args);
debug('createConnection', args);
Expand Down Expand Up @@ -885,9 +884,8 @@ Socket.prototype.connect = function(options, cb) {
// Old API:
// connect(port, [host], [cb])
// connect(path, [cb]);
const argsLen = arguments.length;
var args = new Array(argsLen);
for (var i = 0; i < argsLen; i++)
var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i++)
args[i] = arguments[i];
args = normalizeConnectArgs(args);
return Socket.prototype.connect.apply(this, args);
Expand Down