lib: cache process.binding(…) wrappers#38132
Conversation
| if (!result) { | ||
| result = factory(); | ||
| } |
There was a problem hiding this comment.
| if (!result) { | |
| result = factory(); | |
| } | |
| result ||= factory(); |
but do we want falsy or nullish?
| if (!result) { | |
| result = factory(); | |
| } | |
| result ??= factory(); |
There was a problem hiding this comment.
Arguably, it can just be return result ??= factory().
There was a problem hiding this comment.
Arguably, it can just be
return result ??= factory().
I don't know if we have a linter rule enforcing that, but I think we tend to avoid mixing assignments and return statements in the code base, to improve readability.
There was a problem hiding this comment.
There are a couple of assignments in return statements:
$ git grep "return .* = " libSince this is a smallish statement, should we prefer return result ??= factory();?
There was a problem hiding this comment.
Arguably, it can just be
return result ??= factory().I don't know if we have a linter rule enforcing that, but I think we tend to avoid mixing assignments and return statements in the code base, to improve readability.
Why would that improve readability?
|
Could we avoid the |
To be frank – Why do we care? This is not something that userland code would be expected to rely on, and the point here is to reduce maintenance overhead by putting code in a separate file and not caring about that beyond minimal maintenance. Yes, it’s a bit slower to access the bindings this way, but that’s just fine too. |
b2c15cd to
b57a517
Compare
|
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
|
Closing this because it has stalled. Feel free to reopen if this issue/PR is still relevant, or to ping the collaborator who labelled it stalled if you have any questions. |
Currently,
process.binding("util") === process.binding("util")istrue, this ensures that with #37819,process.binding("util") === process.binding("util")remainstrue.Refs: #37819