Skip to content

optimize UTF8 conversion routines #1022

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

Merged
merged 25 commits into from
Jan 25, 2020
Merged

optimize UTF8 conversion routines #1022

merged 25 commits into from
Jan 25, 2020

Conversation

MaxGraey
Copy link
Member

No description provided.

if ((u0 & 240) == 224) {
u0 = (u0 & 15) << 12 | u1 << 6 | u2;
} else {
if (bufEnd == bufOff) break;
Copy link
Member

Choose a reason for hiding this comment

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

On a first glimpse this seems to be trading branches, like where we previously checked that we can process 3 bytes (never emitting truncated bytes), we now check per byte (potentially emitting truncated bytes?). Makes me wonder what's better.

@MaxGraey MaxGraey changed the title optimize UTF8.decodeUnsafe optimize UTF8.decodeUnsafe + refactor UTF8.byteLength Jan 10, 2020
@MaxGraey MaxGraey changed the title optimize UTF8.decodeUnsafe + refactor UTF8.byteLength optimize UTF8 routines Jan 24, 2020
@MaxGraey MaxGraey changed the title optimize UTF8 routines optimize UTF8 conversion routines Jan 25, 2020
if (nullTerminated && !c1) break;
bufLen += 1; strOff += 2;
// @ts-ignore: cast
if (nullTerminated & !c1) break;
Copy link
Member

@dcodeIO dcodeIO Jan 25, 2020

Choose a reason for hiding this comment

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

Can also do u32(nullTerminated) & u32(!c1) here to avoid the ts-ignore.

Copy link
Member Author

@MaxGraey MaxGraey Jan 25, 2020

Choose a reason for hiding this comment

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

Yes, and in first version I used exactly that but later we decide just comment with ts ignorance)

Copy link
Member Author

Choose a reason for hiding this comment

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

It was in other PR

Copy link
Member

Choose a reason for hiding this comment

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

I see, hmm. Do you remember if that was due to wrapping?

let u0 = <u32>load<u8>(bufOff); ++bufOff;
if (!(u0 & 128)) {
// @ts-ignore: cast
if (nullTerminated & !u0) break;
Copy link
Member

Choose a reason for hiding this comment

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

Similar

@dcodeIO dcodeIO merged commit d11db68 into AssemblyScript:master Jan 25, 2020
@MaxGraey MaxGraey deleted the optimize-str-encodings branch January 25, 2020 16:58
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