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