Skip to content

Commit 94c3f85

Browse files
authored
Make second argument of UTF8ArrayToString optional. NFC (#22696)
This is mostly a wash from a code size POV but makes the call sites more readable I think.
1 parent 2be0e88 commit 94c3f85

25 files changed

+31
-31
lines changed

src/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ addToLibrary({
15341534
emscripten_log__deps: ['$formatString', '$emscriptenLog'],
15351535
emscripten_log: (flags, format, varargs) => {
15361536
var result = formatString(format, varargs);
1537-
var str = UTF8ArrayToString(result, 0);
1537+
var str = UTF8ArrayToString(result);
15381538
emscriptenLog(flags, str);
15391539
},
15401540

src/library_fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ FS.staticInit();
13031303
var buf = new Uint8Array(length);
13041304
FS.read(stream, buf, 0, length, 0);
13051305
if (opts.encoding === 'utf8') {
1306-
ret = UTF8ArrayToString(buf, 0);
1306+
ret = UTF8ArrayToString(buf);
13071307
} else if (opts.encoding === 'binary') {
13081308
ret = buf;
13091309
}

src/library_strings.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ addToLibrary({
2020
* array that contains uint8 values, returns a copy of that string as a
2121
* Javascript String object.
2222
* heapOrArray is either a regular array, or a JavaScript typed array view.
23-
* @param {number} idx
23+
* @param {number=} idx
2424
* @param {number=} maxBytesToRead
2525
* @return {string}
2626
*/`,
2727
#if TEXTDECODER
2828
$UTF8ArrayToString__deps: ['$UTF8Decoder'],
2929
#endif
30-
$UTF8ArrayToString: (heapOrArray, idx, maxBytesToRead) => {
30+
$UTF8ArrayToString: (heapOrArray, idx = 0, maxBytesToRead = NaN) => {
3131
#if CAN_ADDRESS_2GB
3232
idx >>>= 0;
3333
#endif
@@ -38,7 +38,7 @@ addToLibrary({
3838
// null terminator by itself. Also, use the length info to avoid running tiny
3939
// strings through TextDecoder, since .subarray() allocates garbage.
4040
// (As a tiny code save trick, compare endPtr against endIdx using a negation,
41-
// so that undefined means Infinity)
41+
// so that undefined/NaN means Infinity)
4242
while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
4343
#endif // TEXTDECODER
4444

src/library_tty.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ addToLibrary({
106106
},
107107
put_char(tty, val) {
108108
if (val === null || val === {{{ charCode('\n') }}}) {
109-
out(UTF8ArrayToString(tty.output, 0));
109+
out(UTF8ArrayToString(tty.output));
110110
tty.output = [];
111111
} else {
112112
if (val != 0) tty.output.push(val); // val == 0 would cut text output off in the middle.
113113
}
114114
},
115115
fsync(tty) {
116116
if (tty.output && tty.output.length > 0) {
117-
out(UTF8ArrayToString(tty.output, 0));
117+
out(UTF8ArrayToString(tty.output));
118118
tty.output = [];
119119
}
120120
},
@@ -143,15 +143,15 @@ addToLibrary({
143143
default_tty1_ops: {
144144
put_char(tty, val) {
145145
if (val === null || val === {{{ charCode('\n') }}}) {
146-
err(UTF8ArrayToString(tty.output, 0));
146+
err(UTF8ArrayToString(tty.output));
147147
tty.output = [];
148148
} else {
149149
if (val != 0) tty.output.push(val);
150150
}
151151
},
152152
fsync(tty) {
153153
if (tty.output && tty.output.length > 0) {
154-
err(UTF8ArrayToString(tty.output, 0));
154+
err(UTF8ArrayToString(tty.output));
155155
tty.output = [];
156156
}
157157
}

src/library_wasi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ var WasiLibrary = {
245245
assert(buffer);
246246
#endif
247247
if (curr === 0 || curr === {{{ charCode('\n') }}}) {
248-
(stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
248+
(stream === 1 ? out : err)(UTF8ArrayToString(buffer));
249249
buffer.length = 0;
250250
} else {
251251
buffer.push(curr);

src/library_wasmfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ FS.init();
146146
// The buffer contents exist 8 bytes after the returned pointer.
147147
var ret = new Uint8Array(HEAPU8.subarray(buf + 8, buf + 8 + length));
148148
if (opts.encoding === 'utf8') {
149-
ret = UTF8ArrayToString(ret, 0);
149+
ret = UTF8ArrayToString(ret);
150150
}
151151

152152
return ret;

src/source_map_support.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ if (!isDataURI(wasmSourceMapFile)) {
103103

104104
function getSourceMap() {
105105
var buf = readBinary(wasmSourceMapFile);
106-
return JSON.parse(UTF8ArrayToString(buf, 0, buf.length));
106+
return JSON.parse(UTF8ArrayToString(buf));
107107
}
108108

109109
function getSourceMapPromise() {

test/js_optimizer/applyImportAndExportNameChanges2-output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ var SYSCALLS = {
101101
printChar: function(stream, curr) {
102102
var buffer = SYSCALLS.buffers[stream];
103103
if (curr === 0 || curr === 10) {
104-
(stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
104+
(stream === 1 ? out : err)(UTF8ArrayToString(buffer));
105105
buffer.length = 0;
106106
} else {
107107
buffer.push(curr);

test/js_optimizer/applyImportAndExportNameChanges2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ var SYSCALLS = {
8787
printChar: (function(stream, curr) {
8888
var buffer = SYSCALLS.buffers[stream];
8989
if (curr === 0 || curr === 10) {
90-
(stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
90+
(stream === 1 ? out : err)(UTF8ArrayToString(buffer));
9191
buffer.length = 0
9292
} else {
9393
buffer.push(curr)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3899
1+
3894

0 commit comments

Comments
 (0)