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 StringEscapeHelper escape and unescape allocations #46

Merged
merged 1 commit into from Jun 7, 2019
Merged

Reduce StringEscapeHelper escape and unescape allocations #46

merged 1 commit into from Jun 7, 2019

Conversation

slandelle
Copy link
Collaborator

Motivation:

  • StringEscapeHelper allocates StringBuilder of default size (16) so there's a good chance it will either be too large, or too small and reallocate underlying char array.
  • escaped always allocate StringBuilder, even when there's nothing to escape in the input String.

Modifications:

  • Set StringBuilder initial capacity
  • lazy allocate escape's StringBuilder

Result:

Less allocations.

Motivation:

* StringEscapeHelper allocates StringBuilder of default size (16) so there's a good chance it will either be too large, or too small and reallocate underlying char array.
* escaped always allocate StringBuilder, even when there's nothing to escape in the input String.

Modifications:

* Set StringBuilder initial capacity
* lazy allocate escape's StringBuilder

Result:

Less allocations.
@slandelle
Copy link
Collaborator Author

ping @iconara

Copy link
Collaborator

@iconara iconara left a comment

Choose a reason for hiding this comment

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

LGTM

@iconara iconara merged commit 8f007ca into burtcorp:master Jun 7, 2019
@slandelle slandelle deleted the string-escape-helper-optim branch June 7, 2019 08:28
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