MCPcopy Create free account
hub / github.com/Noumena-Network/code / intern

Method intern

src/ink/screen.ts:31–50  ·  view source on GitHub ↗
(char: string)

Source from the content-addressed store, hash-verified

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] ?? ' '

Callers 9

flushBufferFunction · 0.45
fillRawStylesFunction · 0.45
screen.test.tsFile · 0.45
internHyperlinkFunction · 0.45
migrateScreenPoolsFunction · 0.45
internCharStringFunction · 0.45

Calls 2

setMethod · 0.80
getMethod · 0.45

Tested by 1

fillRawStylesFunction · 0.36