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

Implement CharSequences#parseLong(CharSequence) #1469

Merged
merged 9 commits into from
Apr 2, 2021

Conversation

idelpivnitskiy
Copy link
Member

Motivation:

Our HttpHeaders API uses CharSequence. In order for users to parse
the value (like, Content-Length) they have to convert CharSequence
to String for Long.parseLong(String) API. This approach does an extra
copy of data from underlying Buffer. We can avoid it.

Modifications:

  • Add CharSequences#parseLong(CharSequence) API that does not force
    CharSequence#toString() conversion;
  • Add tests to validate new API;
  • Use the new API in all places when we parse an AsciiBuffer or
    AsciiString;

Result:

Less allocations of String.

This PR depends on #1468 (ignore first commit).

Motivation:

0.5.x plugin version can not run newer JMH versions.
Motivation:

Our `HttpHeaders` API uses `CharSequence`. In order for users to parse
the value (like, `Content-Length`) they have to convert `CharSequence`
to `String` for `Long.parseLong(String)` API. This approach does an extra
copy if data from underlying `Buffer`. We can avoid it.

Modifications:

- Add `CharSequences#parseLong(CharSequence)` API that does not force
`CharSequence#toString()` conversion;
- Add tests to validate new API;
- Use the new API in all places when we parse an `AsciiBuffer` or
`AsciiString`;

Result:

Less allocations of `String`.
Copy link
Contributor

@bondolo bondolo left a comment

Choose a reason for hiding this comment

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

Looks good except for the one use of Character.digit()

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.

2 participants