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 { ...@@ -41,20 +41,23 @@ namespace UnitRings {
export function create(unit: Unit.Atomic): UnitRings { export function create(unit: Unit.Atomic): UnitRings {
const rings = computeRings(unit); const rings = computeRings(unit);
const byFingerprint = new Map<string, Index[]>();
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]);
idx++;
}
let _byFingerprint: Map<string, Index[]> | undefined = void 0;
let _index: UnitRings['index'] | undefined = void 0; let _index: UnitRings['index'] | undefined = void 0;
return { return {
all: rings, all: rings,
byFingerprint, 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]);
idx++;
}
return _byFingerprint;
},
get index() { get index() {
if (_index) return _index; if (_index) return _index;
_index = createIndex(rings); _index = createIndex(rings);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment