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

Simplify hex methods #347

Closed
wants to merge 1 commit into from
Closed

Simplify hex methods #347

wants to merge 1 commit into from

Conversation

Jatie1
Copy link

@Jatie1 Jatie1 commented Dec 11, 2024

Update methods encodeHex and decodeHex to simplify the code and make it slightly more efficient.

encodeHex: don't compute dataOffset + dataLen on every for iteration and also standardize nibble high and low using Base16.encode() as inspiration. I would say it's easier to read now.

decodeHex: get high and low nibble directly using for loop iterator incrementing by 2 (2 char per hex val) and OR them immediately instead of getting high nibble, iterating variable, ORing low nibble, iterating variable then converting to byte. I think it's far more readable this way.

I tested both with a barebones jmh benchmark and speed is roughly the same or very slightly faster than old implementation for both.

@garydgregory
Copy link
Member

Hello @Jatie1

Please update the PR so anyone can run your JMH benchmarks.

Thank you!

@garydgregory
Copy link
Member

Closing: No reply in 2 weeks.

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