This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
buffer: make SlowBuffer inherit from Buffer #3228
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I wanted people to comment on this one because it's somewhat controversial. To anyone who doesn't like the
__proto__
usage, the justification is that we do the same thing to theprocess
object to make it be an EventEmtter.But basically this frees us from manually having to copy over functions to SlowBuffer's prototype (which has bitten us multiple times in the past). It's also nice for modules like
buffertools
or my newref
which extend Buffer's prototype, and therefore wouldn't have to do so for SlowBuffer as well.As an added bonus, the
inspect()
function is now shared between Buffer and SlowBuffer, removing some duplicate code. There's probably more functions that we could share, but I figured there's probably speed optimizations that should be left in place.Thoughts?
/cc @isaacs @bnoordhuis @piscisaureus