MCPcopy
hub / github.com/codeaashu/claude-code / cachedHighlight

Function cachedHighlight

src/components/HighlightedCode/Fallback.tsx:21–38  ·  view source on GitHub ↗
(hl: NonNullable<Awaited<ReturnType<typeof getCliHighlightPromise>>>, code: string, language: string)

Source from the content-addressed store, hash-verified

19const HL_CACHE_MAX = 500;
20const hlCache = new Map<string, string>();
21function cachedHighlight(hl: NonNullable<Awaited<ReturnType<typeof getCliHighlightPromise>>>, code: string, language: string): string {
22 const key = hashPair(language, code);
23 const hit = hlCache.get(key);
24 if (hit !== undefined) {
25 hlCache.delete(key);
26 hlCache.set(key, hit);
27 return hit;
28 }
29 const out = hl.highlight(code, {
30 language
31 });
32 if (hlCache.size >= HL_CACHE_MAX) {
33 const first = hlCache.keys().next().value;
34 if (first !== undefined) hlCache.delete(first);
35 }
36 hlCache.set(key, out);
37 return out;
38}
39export function HighlightedCodeFallback(t0) {
40 const $ = _c(20);
41 const {

Callers 1

HighlightedFunction · 0.85

Calls 6

hashPairFunction · 0.85
nextMethod · 0.80
keysMethod · 0.80
getMethod · 0.65
deleteMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected