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

net: improve performance by destructuring primordials #30447

Closed
wants to merge 4 commits into from
Closed
Changes from 2 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
34 changes: 17 additions & 17 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

const { Object } = primordials;
const { Object: { defineProperty, setPrototypeOf } } = primordials;

const EventEmitter = require('events');
const stream = require('stream');
Expand Down Expand Up @@ -336,7 +336,7 @@ function Socket(options) {
// makeSyncWrite adjusts this value like the original handle would, so
// we need to let it do that by turning it into a writable, own
// property.
Object.defineProperty(this._handle, 'bytesWritten', {
defineProperty(this._handle, 'bytesWritten', {
value: 0, writable: true
});
}
Expand Down Expand Up @@ -372,8 +372,8 @@ function Socket(options) {
this[kBytesRead] = 0;
this[kBytesWritten] = 0;
}
Object.setPrototypeOf(Socket.prototype, stream.Duplex.prototype);
Object.setPrototypeOf(Socket, stream.Duplex);
setPrototypeOf(Socket.prototype, stream.Duplex.prototype);
This conversation was marked as resolved.
Show resolved Hide resolved
setPrototypeOf(Socket, stream.Duplex);

// Refresh existing timeouts.
Socket.prototype._unrefTimer = function _unrefTimer() {
Expand Down Expand Up @@ -503,21 +503,21 @@ Socket.prototype.address = function() {
};


Object.defineProperty(Socket.prototype, '_connecting', {
defineProperty(Socket.prototype, '_connecting', {
get: function() {
return this.connecting;
}
});

Object.defineProperty(Socket.prototype, 'pending', {
defineProperty(Socket.prototype, 'pending', {
get() {
return !this._handle || this.connecting;
},
configurable: true
});


Object.defineProperty(Socket.prototype, 'readyState', {
defineProperty(Socket.prototype, 'readyState', {
get: function() {
if (this.connecting) {
return 'opening';
Expand All @@ -534,15 +534,15 @@ Object.defineProperty(Socket.prototype, 'readyState', {
});


Object.defineProperty(Socket.prototype, 'bufferSize', {
get: function() { // eslint-disable-line getter-return
defineProperty(Socket.prototype, 'bufferSize', {
get: function() {
lundibundi marked this conversation as resolved.
Show resolved Hide resolved
if (this._handle) {
return this[kLastWriteQueueSize] + this.writableLength;
}
}
});

Object.defineProperty(Socket.prototype, kUpdateTimer, {
defineProperty(Socket.prototype, kUpdateTimer, {
get: function() {
return this._unrefTimer;
}
Expand Down Expand Up @@ -690,7 +690,7 @@ Socket.prototype._getpeername = function() {
};

function protoGetter(name, callback) {
Object.defineProperty(Socket.prototype, name, {
defineProperty(Socket.prototype, name, {
configurable: false,
enumerable: true,
get: callback
Expand Down Expand Up @@ -1162,7 +1162,7 @@ function Server(options, connectionListener) {

this._connections = 0;

Object.defineProperty(this, 'connections', {
defineProperty(this, 'connections', {
get: deprecate(() => {

if (this._usingWorkers) {
Expand All @@ -1186,8 +1186,8 @@ function Server(options, connectionListener) {
this.allowHalfOpen = options.allowHalfOpen || false;
this.pauseOnConnect = !!options.pauseOnConnect;
}
Object.setPrototypeOf(Server.prototype, EventEmitter.prototype);
Object.setPrototypeOf(Server, EventEmitter);
setPrototypeOf(Server.prototype, EventEmitter.prototype);
setPrototypeOf(Server, EventEmitter);


function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; }
Expand Down Expand Up @@ -1491,7 +1491,7 @@ function lookupAndListen(self, port, address, backlog, exclusive, flags) {
});
}

Object.defineProperty(Server.prototype, 'listening', {
defineProperty(Server.prototype, 'listening', {
get: function() {
return !!this._handle;
},
Expand Down Expand Up @@ -1648,12 +1648,12 @@ function emitCloseNT(self) {

// Legacy alias on the C++ wrapper object. This is not public API, so we may
// want to runtime-deprecate it at some point. There's no hurry, though.
Object.defineProperty(TCP.prototype, 'owner', {
defineProperty(TCP.prototype, 'owner', {
get() { return this[owner_symbol]; },
set(v) { return this[owner_symbol] = v; }
});

Object.defineProperty(Socket.prototype, '_handle', {
defineProperty(Socket.prototype, '_handle', {
get() { return this[kHandle]; },
set(v) { return this[kHandle] = v; }
});
Expand Down