Conversation
* Don't copy the source bytes when we can access an underlying array. * Advance the incoming buffer the number of bytes that were written.
The CRuby logic here will use binwrite when the target has a real fd associated with it, which loops until everything is written, and does a single dynamic "write" call when the target is a pseudo-IO. This patch simulates this behavior by bailing out after as single write when the target channel is wrapping a pseudo-IO. Fixes jruby#6555
When the incoming bytes are on the heap, we can use them in-place for the string we pass to the Ruby write method. However, since the target IO-like may want to modify the incoming string, we must make sure it is marked as shared so our original src bytes will not be modified. This issue originally manifested in jruby#4903 and was fixed by always copying the incoming buffer, but marking the string shared has the same effecit if the target attempts to make any modifications.
fdb251b to
f838b84
Compare
headius
added a commit
to headius/jruby
that referenced
this pull request
Aug 5, 2021
The "optimizations" here were overzealous: * The incoming ByteBuffer and its contents should not be referenced past the end of the call, as was done here by returning a String that directly wraps the buffer's underlying array. * The copy of bytes out of the native buffer is essentially the same as calling #duplicate, so this is just unnecessary double- copying. Fixes jruby#6767.
headius
added a commit
that referenced
this pull request
Aug 5, 2021
Undo shared-buffer optimizations from #6557
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The last item fixes #6555.