Skip to content

Commit 9c97617

Browse files
committed
Revert "what if simplify readString?"
This reverts commit f4debe6.
1 parent f4debe6 commit 9c97617

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/module.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,18 +2397,18 @@ function readBuffer(ptr: usize, len: i32): Uint8Array {
23972397

23982398
export function readString(ptr: usize): string | null {
23992399
if (!ptr) return null;
2400-
var str = "";
2400+
var arr = new Array<i32>();
24012401
// the following is based on Emscripten's UTF8ArrayToString
24022402
var cp: u32;
24032403
var u1: u32, u2: u32, u3: u32, u4: u32, u5: u32;
24042404
while (cp = binaryen.__i32_load8_u(ptr++)) {
24052405
if (!(cp & 0x80)) {
2406-
str += String.fromCharCode(cp);
2406+
arr.push(cp);
24072407
continue;
24082408
}
24092409
u1 = binaryen.__i32_load8_u(ptr++) & 63;
24102410
if ((cp & 0xE0) == 0xC0) {
2411-
str += String.fromCharCode(((cp & 31) << 6) | u1);
2411+
arr.push(((cp & 31) << 6) | u1);
24122412
continue;
24132413
}
24142414
u2 = binaryen.__i32_load8_u(ptr++) & 63;
@@ -2428,16 +2428,16 @@ export function readString(ptr: usize): string | null {
24282428
}
24292429
}
24302430
}
2431-
str += String.fromCharCode(cp);
2431+
arr.push(cp);
24322432
if (cp < 0x10000) {
2433-
str += String.fromCharCode(cp);
2433+
arr.push(cp);
24342434
} else {
24352435
let ch = cp - 0x10000;
2436-
str += String.fromCharCode(0xD800 | (ch >>> 10)) +
2437-
String.fromCharCode(0xDC00 | (ch & 0x3FF));
2436+
arr.push(0xD800 | (ch >>> 10));
2437+
arr.push(0xDC00 | (ch & 0x3FF));
24382438
}
24392439
}
2440-
return str;
2440+
return String.fromCharCodes(arr);
24412441
}
24422442

24432443
/** Result structure of {@link Module#toBinary}. */

0 commit comments

Comments
 (0)