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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/lib/libatomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ addToLibrary({
// https://github.com/tc39/proposal-atomics-wait-async/blob/master/PROPOSAL.md
// This polyfill performs polling with setTimeout() to observe a change in the
// target memory location.
$polyfillWaitAsync__postset: `if (!Atomics.waitAsync || (typeof navigator != 'undefined' && navigator.userAgent && jstoi_q((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91)) {
$polyfillWaitAsync__postset: `if (!Atomics.waitAsync || (typeof navigator != 'undefined' && navigator.userAgent && Number((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91)) {
let __Atomics_waitAsyncAddresses = [/*[i32a, index, value, maxWaitMilliseconds, promiseResolve]*/];
function __Atomics_pollWaitAsyncAddresses() {
let now = performance.now();
Expand Down Expand Up @@ -60,7 +60,6 @@ addToLibrary({
return { async: true, value: promise };
};
}`,
$polyfillWaitAsync__deps: ['$jstoi_q'],
#endif

$polyfillWaitAsync__internal: true,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libc_preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ addToLibrary({
// Runs C preprocessor algorithm on the given string 'code'.
// Supported preprocessor directives: #if, #ifdef, #ifndef, #else, #elif, #endif, #define and #undef.
// predefs: Specifies a dictionary of { 'key1': function(arg0, arg1) {...}, 'key2': ... } of predefined preprocessing variables
$preprocess_c_code__deps: ['$jstoi_q', '$find_closing_parens_index'],
$preprocess_c_code__deps: ['$find_closing_parens_index'],
$preprocess_c_code: function(code, defs = {}) {
var i = 0, // iterator over the input string
len = code.length, // cache input length
Expand Down Expand Up @@ -207,7 +207,7 @@ addToLibrary({
if (tokens[i] == ')') throw 'Parsing failure, mismatched parentheses in parsing!' + tokens.toString();
assert(operatorAndPriority == -1);
#endif
var num = jstoi_q(tokens[i]);
var num = Number(tokens[i]);
return [function() { return num; }]
})(tokens);
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/libcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ addToLibrary({
},
$inetNtop4: (addr) =>
(addr & 0xff) + '.' + ((addr >> 8) & 0xff) + '.' + ((addr >> 16) & 0xff) + '.' + ((addr >> 24) & 0xff),
$inetPton6__deps: ['htons', '$jstoi_q'],
$inetPton6__deps: ['htons'],
$inetPton6: (str) => {
var words;
var w, offset, z, i;
Expand All @@ -671,8 +671,8 @@ addToLibrary({
// parse IPv4 embedded stress
str = str.replace(new RegExp('[.]', 'g'), ":");
words = str.split(":");
words[words.length-4] = jstoi_q(words[words.length-4]) + jstoi_q(words[words.length-3])*256;
words[words.length-3] = jstoi_q(words[words.length-2]) + jstoi_q(words[words.length-1])*256;
words[words.length-4] = Number(words[words.length-4]) + Number(words[words.length-3])*256;
words[words.length-3] = Number(words[words.length-2]) + Number(words[words.length-1])*256;
words = words.slice(0, words.length-2);
} else {
words = str.split(":");
Expand Down
26 changes: 13 additions & 13 deletions src/lib/libtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ addToLibrary({
},

strptime__deps: ['$isLeapYear', '$arraySum', '$addDays', '$MONTH_DAYS_REGULAR', '$MONTH_DAYS_LEAP',
'$jstoi_q', '$intArrayFromString' ],
'$intArrayFromString' ],
strptime: (buf, format, tm) => {
// char *strptime(const char *restrict buf, const char *restrict format, struct tm *restrict tm);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html
Expand Down Expand Up @@ -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.

}

// minutes
if ((value=getMatch('M'))) {
date.min = jstoi_q(value);
date.min = Number(value);
}

// hours
if ((value=getMatch('H'))) {
// 24h clock
date.hour = jstoi_q(value);
date.hour = Number(value);
} else if ((value = getMatch('I'))) {
// AM/PM clock
var hour = jstoi_q(value);
var hour = Number(value);
if ((value=getMatch('p'))) {
hour += value.toUpperCase()[0] === 'P' ? 12 : 0;
}
Expand All @@ -386,13 +386,13 @@ addToLibrary({
// year
if ((value=getMatch('Y'))) {
// parse from four-digit year
date.year = jstoi_q(value);
date.year = Number(value);
} else if ((value=getMatch('y'))) {
// parse from two-digit year...
var year = jstoi_q(value);
var year = Number(value);
if ((value=getMatch('C'))) {
// ...and century
year += jstoi_q(value)*100;
year += Number(value)*100;
} else {
// ...and rule-of-thumb
year += year<69 ? 2000 : 1900;
Expand All @@ -403,7 +403,7 @@ addToLibrary({
// month
if ((value=getMatch('m'))) {
// parse from month number
date.month = jstoi_q(value)-1;
date.month = Number(value)-1;
} else if ((value=getMatch('b'))) {
// parse from month name
date.month = MONTH_NUMBERS[value.substring(0,3).toUpperCase()] || 0;
Expand All @@ -413,10 +413,10 @@ addToLibrary({
// day
if ((value=getMatch('d'))) {
// get day of month directly
date.day = jstoi_q(value);
date.day = Number(value);
} else if ((value=getMatch('j'))) {
// get day of month from day of year ...
var day = jstoi_q(value);
var day = Number(value);
var leapYear = isLeapYear(date.year);
for (var month=0; month<12; ++month) {
var daysUntilMonth = arraySum(leapYear ? MONTH_DAYS_LEAP : MONTH_DAYS_REGULAR, month-1);
Expand All @@ -432,7 +432,7 @@ addToLibrary({
// Week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
// All days in a new year preceding the first Sunday are considered to be in week 0.
var weekDayNumber = DAY_NUMBERS_SUN_FIRST[weekDay];
var weekNumber = jstoi_q(value);
var weekNumber = Number(value);

// January 1st
var janFirst = new Date(date.year, 0, 1);
Expand All @@ -451,7 +451,7 @@ addToLibrary({
// Week number of the year (Monday as the first day of the week) as a decimal number [00,53].
// All days in a new year preceding the first Monday are considered to be in week 0.
var weekDayNumber = DAY_NUMBERS_MON_FIRST[weekDay];
var weekNumber = jstoi_q(value);
var weekNumber = Number(value);

// January 1st
var janFirst = new Date(date.year, 0, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libwebgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...

#if GL_TRACK_ERRORS
if (!(explicitUniformLocations[match[5]] >= 0 && explicitUniformLocations[match[5]] < 1048576)) {
err(`Specified an out of range layout(location=x) directive "${explicitUniformLocations[match[5]]}"! (${match[0]})`);
Expand Down