| 19 | // so blitRegion can copy IDs directly (no re-interning) and |
| 20 | // diffEach can compare IDs as integers (no string lookup). |
| 21 | export class CharPool { |
| 22 | private strings: string[] = [' ', ''] // Index 0 = space, 1 = empty (spacer) |
| 23 | private stringMap = new Map<string, number>([ |
| 24 | [' ', 0], |
| 25 | ['', 1], |
| 26 | ]) |
| 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] ?? ' ' |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // Hyperlink string pool shared across all screens. |
| 56 | // Index 0 = no hyperlink. |
nothing calls this directly
no test coverage detected