Skip to content

More performant conversion byte to hexadecimal string - #70

Closed
xtonik wants to merge 2 commits into
wrandelshofer:mainfrom
xtonik:LOOKUP_HEX
Closed

More performant conversion byte to hexadecimal string#70
xtonik wants to merge 2 commits into
wrandelshofer:mainfrom
xtonik:LOOKUP_HEX

Conversation

@xtonik

@xtonik xtonik commented Jun 12, 2023

Copy link
Copy Markdown

No description provided.

// Branch-less code: return CHAR_TO_HEX_MAP[ch & 127] | (127 - ch) >> 31;
return ch < 128 ? CHAR_TO_HEX_MAP[ch] : -1;
static int lookupHex(char ch) {
return CHAR_TO_HEX_MAP[ch & 0xff];

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

return CHAR_TO_HEX_MAP[ch & 0xff];

This code incorrectly maps characters outside of the ASCII range.
For example, the code incorrectly maps the character 'Ł' U+0141 to 'A' U+0041.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You are right, I had to overlook something.

@wrandelshofer

Copy link
Copy Markdown
Owner

I am closing this merge request, because it incorrectly accepts some non-ascii characters as hex characters.
I have added new test cases to the main branch, to help detect this problem.

@xtonik
xtonik deleted the LOOKUP_HEX branch June 16, 2023 11:06
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