-
Notifications
You must be signed in to change notification settings - Fork 30k
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
lib: refactor some lib/internals #11406
Conversation
lib/internal/freelist.js
Outdated
|
||
alloc() { | ||
return this.list.length ? this.list.pop() : | ||
this.constructor.apply(this, arguments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, but perhaps this can be simplified since http
is the only user of FreeList and we'd know how what arguments to pass on to the constructor. I'm not sure if adding new
would help (allowing us to avoid an instanceof
check in the constructor if possible) more than it might hurt (e.g. if stack traces would change with new constructor(..)
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth playing around with. I would also note that I had attempted to replace this use of arguments
with ...args
, but found that in the case there are no arguments passed to the alloc()
, it caused a whopping 48% slowdown. Definitely something we'll need to keep in mind.
lib/internal/net.js
Outdated
@@ -11,8 +9,12 @@ function isLegalPort(port) { | |||
return +port === (+port >>> 0) && port <= 0xFFFF; | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unintended?
lib/internal/freelist.js
Outdated
class FreeList { | ||
constructor(name, max, constructor) { | ||
this.name = name; | ||
this.constructor = constructor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming own properties of instances constructor
is kind of confusing, maybe you could change that while you’re here?
lib/internal/socket_list.js
Outdated
constructor(slave, key) { | ||
super(); | ||
this.key = key; | ||
this.slave = slave; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, it would be awesome if we could change this during the refactor (here and in the other parts of the file this PR touches).
Switch to using the more efficient module.exports = {} where possible.
ebd64f5
to
be22262
Compare
semver-major because an error message is changed. |
PR-URL: #11406 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: #11406 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: #11406 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Switch to using the more efficient module.exports = {} where possible. PR-URL: #11406 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Landed in d61a511...62e9609 |
Some light refactoring of internals/*.js
(do not squash commits)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
lib/internal