| 29 | private ascii: Int32Array = initCharAscii() // charCode → index, -1 = not interned |
| 30 | |
| 31 | intern(char: string): number { |
| 32 | // ASCII fast-path: direct array lookup instead of Map.get |
| 33 | if (char.length === 1) { |
| 34 | const code = char.charCodeAt(0) |
| 35 | if (code < 128) { |
| 36 | const cached = this.ascii[code]! |
| 37 | if (cached !== -1) return cached |
| 38 | const index = this.strings.length |
| 39 | this.strings.push(char) |
| 40 | this.ascii[code] = index |
| 41 | return index |
| 42 | } |
| 43 | } |
| 44 | const existing = this.stringMap.get(char) |
| 45 | if (existing !== undefined) return existing |
| 46 | const index = this.strings.length |
| 47 | this.strings.push(char) |
| 48 | this.stringMap.set(char, index) |
| 49 | return index |
| 50 | } |
| 51 | |
| 52 | get(index: number): string { |
| 53 | return this.strings[index] ?? ' ' |