Skip to content
Snippets Groups Projects
Commit c4f7dd86 authored by David Sehnal's avatar David Sehnal
Browse files

Compute UnitRings.byFingerprint lazily

parent 92b36f8e
No related branches found
No related tags found
No related merge requests found
......@@ -41,20 +41,23 @@ namespace UnitRings {
export function create(unit: Unit.Atomic): UnitRings {
const rings = computeRings(unit);
const byFingerprint = new Map<string, Index[]>();
let _byFingerprint: Map<string, Index[]> | undefined = void 0;
let _index: UnitRings['index'] | undefined = void 0;
return {
all: rings,
get byFingerprint() {
if (_byFingerprint) return _byFingerprint;
_byFingerprint = new Map();
let idx = 0 as Index;
for (const r of rings) {
const fp = getRingFingerprint(unit, r);
if (byFingerprint.has(fp)) byFingerprint.get(fp)!.push(idx);
else byFingerprint.set(fp, [idx]);
if (_byFingerprint.has(fp)) _byFingerprint.get(fp)!.push(idx);
else _byFingerprint.set(fp, [idx]);
idx++;
}
let _index: UnitRings['index'] | undefined = void 0;
return {
all: rings,
byFingerprint,
return _byFingerprint;
},
get index() {
if (_index) return _index;
_index = createIndex(rings);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment