| 1508 | this.buf[p] = n |
| 1509 | } |
| 1510 | string(s: string) { |
| 1511 | const n = s.length |
| 1512 | if (n === 0) return |
| 1513 | this.ensure(n * 3) |
| 1514 | const buf = this.buf |
| 1515 | let p = this.start + this.len |
| 1516 | let i = 0 |
| 1517 | for (; i + 4 <= n; i += 4) { |
| 1518 | const a = s.charCodeAt(i) |
| 1519 | const b = s.charCodeAt(i + 1) |
| 1520 | const c = s.charCodeAt(i + 2) |
| 1521 | const d = s.charCodeAt(i + 3) |
| 1522 | if ((a | b | c | d) > 0x7F) { |
| 1523 | this.len += utf8Encode.encodeInto(s, buf.subarray(this.start + this.len)).written |
| 1524 | return |
| 1525 | } |
| 1526 | buf[p++] = a |
| 1527 | buf[p++] = b |
| 1528 | buf[p++] = c |
| 1529 | buf[p++] = d |
| 1530 | } |
| 1531 | for (; i < n; i++) { |
| 1532 | const c = s.charCodeAt(i) |
| 1533 | if (c > 0x7F) { |
| 1534 | this.len += utf8Encode.encodeInto(s, buf.subarray(this.start + this.len)).written |
| 1535 | return |
| 1536 | } |
| 1537 | buf[p++] = c |
| 1538 | } |
| 1539 | this.len = p - this.start |
| 1540 | } |
| 1541 | out(): Uint8Array<ArrayBuffer> { |
| 1542 | // An assembled frame owns its bytes, so the arena is released as if unused. |
| 1543 | if (this.deferred.length > 0) { |