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

Avoid array copy on LocalResponse.getBodyAsString #93

Merged
merged 7 commits into from
May 25, 2016

Conversation

AlexanderYastrebov
Copy link
Member

@AlexanderYastrebov AlexanderYastrebov commented May 16, 2016

Make withBody noop and getBody create bytearray lazily
Use output's buffer directly in getBodyAsString

@whiskeysierra whiskeysierra modified the milestone: 1.0.0 May 16, 2016
return body;
}

@Override
public String getBodyAsString() throws IOException {
return output.toString(getCharset().name());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't the default implementation doing pretty much the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

Default one uses getBody() which uses output.getByteArray() which makes copy.
So if codepath uses getBodyAsString, this setup avoids array copying by constructing string directly from output.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Default one uses getBody() which uses output.getByteArray() which makes copy.
So if codepath uses getBodyAsString, this setup avoids array copying by constructing string directly from output.

But getBody doesn't do the copying, withBody does and that should only happen once.

Copy link
Member Author

Choose a reason for hiding this comment

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

After this change withBody does not do copy anymore.

@whiskeysierra
Copy link
Collaborator

👍

@whiskeysierra
Copy link
Collaborator

👍

1 similar comment
@AlexanderYastrebov
Copy link
Member Author

+1

@AlexanderYastrebov
Copy link
Member Author

+1

@whiskeysierra
Copy link
Collaborator

@AlexanderYastrebov Can you approve + merge?

@whiskeysierra whiskeysierra merged commit f4f0f6b into master May 25, 2016
@whiskeysierra whiskeysierra deleted the remove-response-double-buffering branch May 25, 2016 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants