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

Reduce garbage generated when searching for MIME attachment delimiters #718

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions data/src/main/java/com/linkedin/data/ByteString.java
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,13 @@ private ByteIterator copy()
return new ByteIterator(this);
}

private void copyFrom(final ByteIterator other)
{
_currentByteArray = other._currentByteArray;
_currentByteIndex = other._currentByteIndex;
_finished = other._finished;
}

private void next()
{
//Shift the internal pointer to the next byte.
Expand Down Expand Up @@ -754,9 +761,7 @@ public int indexOfBytes(byte[] targetBytes)
//There was a mismatch so we reset i and prepare to start over.
i = 0;
//Update byteIterator to point to the next byte where our comparison will begin.
byteIterator = resumeByteIterator;
//Keep track of where to resume in the future.
resumeByteIterator = resumeByteIterator.copy();
byteIterator.copyFrom(resumeByteIterator);
//Skip the next since byteIterator will begin there.
resumeByteIterator.next();
continue;
Expand Down