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

Function lineWidth

src/ink/line-width-cache.ts:10–29  ·  view source on GitHub ↗
(line: string)

Source from the content-addressed store, hash-verified

8const MAX_CACHE_SIZE = 4096
9
10export function lineWidth(line: string): number {
11 const cached = cache.get(line)
12 if (cached !== undefined) return cached
13
14 const width = stringWidth(line)
15
16 // Evict oldest 25% when cache grows too large. Full clear would force
17 // re-measuring every visible line on the next frame.
18 if (cache.size >= MAX_CACHE_SIZE) {
19 const evictCount = Math.floor(cache.size * 0.25)
20 let evicted = 0
21 for (const key of cache.keys()) {
22 cache.delete(key)
23 if (++evicted >= evictCount) break
24 }
25 }
26
27 cache.set(line, width)
28 return width
29}

Callers 2

measureTextFunction · 0.85
widestLineFunction · 0.85

Calls 4

keysMethod · 0.80
deleteMethod · 0.80
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected