Skip to content

net: misc changes #8112

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

Merged
merged 2 commits into from
Aug 23, 2016
Merged
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
16 changes: 8 additions & 8 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
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
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
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 All @@ -75,7 +74,9 @@ exports.connect = exports.createConnection = function() {
function normalizeConnectArgs(args) {
var options = {};

if (args[0] !== null && typeof args[0] === 'object') {
if (args.length === 0) {
return [options];
} else if (args[0] !== null && typeof args[0] === 'object') {
// connect(options, [cb])
options = args[0];
} else if (isPipeName(args[0])) {
Expand All @@ -84,7 +85,7 @@ function normalizeConnectArgs(args) {
} else {
// connect(port, [host], [cb])
options.port = args[0];
if (typeof args[1] === 'string') {
if (args.length > 1 && typeof args[1] === 'string') {
options.host = args[1];
}
}
Expand Down Expand Up @@ -885,9 +886,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