Skip to content

Remove unnecessary usage of jstoi_q. NFC #23791

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 1 commit into from
Mar 3, 2025

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Feb 28, 2025

The jstoi_q was introduced in #10457 because of issues with using parseInt directly and closure compiler. However, in many cases its simpler to just use Number. See google/closure-compiler#3230

Split out from #23789.

@sbc100 sbc100 requested a review from kripken February 28, 2025 01:26
@@ -362,21 +362,21 @@ addToLibrary({

// seconds
if ((value=getMatch('S'))) {
date.sec = jstoi_q(value);
date.sec = Number(value);
Copy link
Member

Choose a reason for hiding this comment

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

The code above is fairly complex - how can I see that this is a pure number without a prefix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The getMatch function returns that result of the regex's above.

You can see that we only call Number on the following matches: S, M, H, I, Y, y, C, m, d, j, U, W.

You can look at the above table of regexes and see that each of them only ever match numbers.

We also have pretty extensive testing for strftime I believe.

@@ -3205,7 +3205,7 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
#if GL_DEBUG
console.dir(match);
#endif
explicitUniformLocations[match[5]] = jstoi_q(match[1]);
explicitUniformLocations[match[5]] = Number(match[1]);
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, is the 5th capture not \w+, which accepts more than digits? Am I computing that wrong, or perhaps does the GL API guarantee an integer here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are using the first capture here aren't we? That looks like (-?\d+) to me

Copy link
Member

Choose a reason for hiding this comment

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

Oh, somehow my eye read the match[5] on the left...

@sbc100 sbc100 force-pushed the remove_jstoi_q_usage branch from f0cf29c to 8e04e4a Compare February 28, 2025 16:47
In most use cases we can just use `Number` instead.

Split out from emscripten-core#23789.
@sbc100 sbc100 force-pushed the remove_jstoi_q_usage branch from 8e04e4a to 542b6b2 Compare February 28, 2025 19:52
@sbc100 sbc100 merged commit 354fdd3 into emscripten-core:main Mar 3, 2025
28 of 29 checks passed
@sbc100 sbc100 deleted the remove_jstoi_q_usage branch March 3, 2025 22:37
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