Skip to content

Commit 42f1869

Browse files
committed
remove redundant cases for allocString & stringLengthUTF8
1 parent 82d3faa commit 42f1869

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

src/glue/wasm/i64.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ function i64_to_f64(value: i64): f64 {
226226
}
227227

228228
// @ts-ignore: decorator
229-
@global
229+
@global @inline
230230
function i64_to_string(value: i64, unsigned: bool = false): string {
231231
return (unsigned ? <u64>value : value).toString();
232232
}

src/module.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,17 +2344,13 @@ function stringLengthUTF8(str: string): usize {
23442344
u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF);
23452345
}
23462346
if (u <= 0x7F) {
2347-
++len;
2347+
len += 1;
23482348
} else if (u <= 0x7FF) {
23492349
len += 2;
23502350
} else if (u <= 0xFFFF) {
23512351
len += 3;
2352-
} else if (u <= 0x1FFFFF) {
2353-
len += 4;
2354-
} else if (u <= 0x3FFFFFF) {
2355-
len += 5;
23562352
} else {
2357-
len += 6;
2353+
len += 4;
23582354
}
23592355
}
23602356
return len;
@@ -2379,21 +2375,9 @@ function allocString(str: string | null): usize {
23792375
binaryen.__i32_store8(idx++, (0xE0 | (u >>> 12) ) as u8);
23802376
binaryen.__i32_store8(idx++, (0x80 | ((u >>> 6) & 63)) as u8);
23812377
binaryen.__i32_store8(idx++, (0x80 | ( u & 63)) as u8);
2382-
} else if (u <= 0x1FFFFF) {
2383-
binaryen.__i32_store8(idx++, (0xF0 | (u >>> 18) ) as u8);
2384-
binaryen.__i32_store8(idx++, (0x80 | ((u >>> 12) & 63)) as u8);
2385-
binaryen.__i32_store8(idx++, (0x80 | ((u >>> 6) & 63)) as u8);
2386-
binaryen.__i32_store8(idx++, (0x80 | ( u & 63)) as u8);
2387-
} else if (u <= 0x3FFFFFF) {
2388-
binaryen.__i32_store8(idx++, (0xF8 | (u >>> 24) ) as u8);
2389-
binaryen.__i32_store8(idx++, (0x80 | ((u >>> 18) & 63)) as u8);
2390-
binaryen.__i32_store8(idx++, (0x80 | ((u >>> 12) & 63)) as u8);
2391-
binaryen.__i32_store8(idx++, (0x80 | ((u >>> 6) & 63)) as u8);
2392-
binaryen.__i32_store8(idx++, (0x80 | ( u & 63)) as u8);
23932378
} else {
2394-
binaryen.__i32_store8(idx++, (0xFC | (u >>> 30) ) as u8);
2395-
binaryen.__i32_store8(idx++, (0x80 | ((u >>> 24) & 63)) as u8);
2396-
binaryen.__i32_store8(idx++, (0x80 | ((u >>> 18) & 63)) as u8);
2379+
assert(u < 0x200000, "Invalid Unicode code point during allocString");
2380+
binaryen.__i32_store8(idx++, (0xF0 | (u >>> 18) ) as u8);
23972381
binaryen.__i32_store8(idx++, (0x80 | ((u >>> 12) & 63)) as u8);
23982382
binaryen.__i32_store8(idx++, (0x80 | ((u >>> 6) & 63)) as u8);
23992383
binaryen.__i32_store8(idx++, (0x80 | ( u & 63)) as u8);

0 commit comments

Comments
 (0)