Files
orca/mobile/patches/xterm-src/@xterm__xterm@6.1.0-beta.303.src.patch
T
Neil 8e34d8a876 fix(terminal): count a contrast-cache pair once toward the entry cap
`_admitNewEntry` fired from both `setCss` and `setColor`, so one (bg, fg)
pair consumed two of the 4096 slots and the cache actually wiped at ~2048
pairs. Track admission in a `_seen` TwoKeyMap keyed by the pair, cleared
with the other maps, so the bound matches the documented constant.

Regenerated the desktop and mobile bundle patches and both lockfile hashes.
2026-09-19 15:04:42 -07:00

51 lines
1.8 KiB
Diff

diff --git a/src/browser/ColorContrastCache.ts b/src/browser/ColorContrastCache.ts
index fdcd9d133199a6cd6ba9bea9606a02c03ad03b3d..e3ba7de0ed63abc451d0f404b86ab690ff9f7440 100644
--- a/src/browser/ColorContrastCache.ts
+++ b/src/browser/ColorContrastCache.ts
@@ -7,11 +7,16 @@ import { IColorContrastCache } from './Types';
import { IColor } from '../common/Types';
import { TwoKeyMap } from '../common/MultiKeyMap';
+const CONTRAST_CACHE_MAX_ENTRIES = 4096;
+
export class ColorContrastCache implements IColorContrastCache {
private _color: TwoKeyMap</* bg */number, /* fg */number, IColor | null> = new TwoKeyMap();
private _css: TwoKeyMap</* bg */number, /* fg */number, string | null> = new TwoKeyMap();
+ private _seen: TwoKeyMap</* bg */number, /* fg */number, boolean> = new TwoKeyMap();
+ private _entryCount = 0;
public setCss(bg: number, fg: number, value: string | null): void {
+ this._admitPair(bg, fg);
this._css.set(bg, fg, value);
}
@@ -20,6 +25,7 @@ export class ColorContrastCache implements IColorContrastCache {
}
public setColor(bg: number, fg: number, value: IColor | null): void {
+ this._admitPair(bg, fg);
this._color.set(bg, fg, value);
}
@@ -30,5 +36,20 @@ export class ColorContrastCache implements IColorContrastCache {
public clear(): void {
this._color.clear();
this._css.clear();
+ this._seen.clear();
+ this._entryCount = 0;
+ }
+
+ private _admitPair(bg: number, fg: number): void {
+ // setColor and setCss both admit, so _seen keeps a pair to one slot.
+ if (this._seen.get(bg, fg) !== undefined) {
+ return;
+ }
+ // Color pairs outlive atlas pages, including cached misses and DOM-rendered colors.
+ if (this._entryCount >= CONTRAST_CACHE_MAX_ENTRIES) {
+ this.clear();
+ }
+ this._seen.set(bg, fg, true);
+ this._entryCount++;
}
}