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

Not cause a CoW when calling ByteBuffer.discardReadBytes() while it wa… #363

Merged
merged 5 commits into from
Apr 27, 2018

Conversation

normanmaurer
Copy link
Member

…s fully consumed.

Motivation:

We should not need to trigger any copy when the ByteBuffer was fully consumed and discardReadBytes() is called.

Modifications:

  • If fully consumed just reset reader and writer Index.
  • Add unit test

Result:

Less memory copies

@normanmaurer normanmaurer changed the title Not case a CoW when calling ByteBuffer.discardReadBytes() while it wa… Not cause a CoW when calling ByteBuffer.discardReadBytes() while it wa… Apr 26, 2018
@@ -550,6 +550,13 @@ public struct ByteBuffer {
return false
}

if self._readerIndex == self.writerIndex {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we hitting different indices here, one underscored and one not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I have fat fingers 🤤 ... Let me fix it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

…as fully consumed.

Motivation:

We should not need to trigger any copy when the ByteBuffer was fully consumed and discardReadBytes() is called.

Modifications:

- If fully consumed just reset reader and writer Index.
- Add unit test

Result:

Less memory copies
Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@Lukasa Lukasa added the semver/patch No public API change. label Apr 27, 2018
@Lukasa Lukasa added this to the 1.6.0 milestone Apr 27, 2018
@Lukasa Lukasa merged commit e5dedbe into apple:master Apr 27, 2018
@normanmaurer normanmaurer deleted the discard_read_bytes_consumed branch April 27, 2018 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants