-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4081 from Tyriar/more_gc
More garbage collection optimizations for GlyphRenderer
- Loading branch information
Showing
5 changed files
with
175 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright (c) 2018 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import { assert } from 'chai'; | ||
import { FourKeyMap, TwoKeyMap } from 'common/MultiKeyMap'; | ||
|
||
const strictEqual = assert.strictEqual; | ||
|
||
describe('TwoKeyMap', () => { | ||
let map: TwoKeyMap<number | string, number | string, string>; | ||
|
||
beforeEach(() => { | ||
map = new TwoKeyMap(); | ||
}); | ||
|
||
it('set, get', () => { | ||
strictEqual(map.get(1, 2), undefined); | ||
map.set(1, 2, 'foo'); | ||
strictEqual(map.get(1, 2), 'foo'); | ||
map.set(1, 3, 'bar'); | ||
strictEqual(map.get(1, 2), 'foo'); | ||
strictEqual(map.get(1, 3), 'bar'); | ||
map.set(2, 2, 'foo2'); | ||
map.set(2, 3, 'bar2'); | ||
strictEqual(map.get(1, 2), 'foo'); | ||
strictEqual(map.get(1, 3), 'bar'); | ||
strictEqual(map.get(2, 2), 'foo2'); | ||
strictEqual(map.get(2, 3), 'bar2'); | ||
}); | ||
it('clear', () => { | ||
strictEqual(map.get(1, 2), undefined); | ||
map.set(1, 2, 'foo'); | ||
strictEqual(map.get(1, 2), 'foo'); | ||
map.clear(); | ||
strictEqual(map.get(1, 2), undefined); | ||
}); | ||
}); | ||
|
||
describe('FourKeyMap', () => { | ||
let map: FourKeyMap<number | string, number | string, number | string, number | string, string>; | ||
|
||
beforeEach(() => { | ||
map = new FourKeyMap(); | ||
}); | ||
|
||
it('set, get', () => { | ||
strictEqual(map.get(1, 2, 3, 4), undefined); | ||
map.set(1, 2, 3, 4, 'foo'); | ||
strictEqual(map.get(1, 2, 3, 4), 'foo'); | ||
map.set(1, 3, 3, 4, 'bar'); | ||
strictEqual(map.get(1, 2, 3, 4), 'foo'); | ||
strictEqual(map.get(1, 3, 3, 4), 'bar'); | ||
map.set(2, 2, 3, 4, 'foo2'); | ||
map.set(2, 3, 3, 4, 'bar2'); | ||
strictEqual(map.get(1, 2, 3, 4), 'foo'); | ||
strictEqual(map.get(1, 3, 3, 4), 'bar'); | ||
strictEqual(map.get(2, 2, 3, 4), 'foo2'); | ||
strictEqual(map.get(2, 3, 3, 4), 'bar2'); | ||
}); | ||
it('clear', () => { | ||
strictEqual(map.get(1, 2, 3, 4), undefined); | ||
map.set(1, 2, 3, 4, 'foo'); | ||
strictEqual(map.get(1, 2, 3, 4), 'foo'); | ||
map.clear(); | ||
strictEqual(map.get(1, 2, 3, 4), undefined); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2022 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
export class TwoKeyMap<TFirst extends string | number, TSecond extends string | number, TValue> { | ||
private _data: { [bg: string | number]: { [fg: string | number]: TValue | undefined } | undefined } = {}; | ||
|
||
public set(first: TFirst, second: TSecond, value: TValue): void { | ||
if (!this._data[first]) { | ||
this._data[first] = {}; | ||
} | ||
this._data[first as string | number]![second] = value; | ||
} | ||
|
||
public get(first: TFirst, second: TSecond): TValue | undefined { | ||
return this._data[first as string | number] ? this._data[first as string | number]![second] : undefined; | ||
} | ||
|
||
public clear(): void { | ||
this._data = {}; | ||
} | ||
} | ||
|
||
export class FourKeyMap<TFirst extends string | number, TSecond extends string | number, TThird extends string | number, TFourth extends string | number, TValue> { | ||
private _data: TwoKeyMap<TFirst, TSecond, TwoKeyMap<TThird, TFourth, TValue>> = new TwoKeyMap(); | ||
|
||
public set(first: TFirst, second: TSecond, third: TThird, fourth: TFourth, value: TValue): void { | ||
if (!this._data.get(first, second)) { | ||
this._data.set(first, second, new TwoKeyMap()); | ||
} | ||
this._data.get(first, second)!.set(third, fourth, value); | ||
} | ||
|
||
public get(first: TFirst, second: TSecond, third: TThird, fourth: TFourth): TValue | undefined { | ||
return this._data.get(first, second)?.get(third, fourth); | ||
} | ||
|
||
public clear(): void { | ||
this._data.clear(); | ||
} | ||
} |