refactor(desktop): index unique positional key values directly (#17316)

This commit is contained in:
Vincent Koc
2026-12-06 08:32:53 +08:00
committed by GitHub
parent 0d425cc445
commit 3a4c156881
+7 -11
View File
@@ -38,19 +38,15 @@ const sequenceStarts = (members: readonly Record<string, string>[]) => {
/** Each member another attribute's value names alone among `members`, by that attribute and value. */
const aloneBy = (members: readonly Record<string, string>[], other: string) => {
const counts = new Map<string, number>();
for (const member of members) {
// A negative index marks a value that occurs more than once.
const indexes = new Map<string, number>();
for (const [index, member] of members.entries()) {
const value = member[other];
if (value !== undefined) counts.set(value, (counts.get(value) ?? 0) + 1);
if (value !== undefined)
indexes.set(value, indexes.has(value) ? -1 : index);
}
return new Map(
members.flatMap((member, index) => {
const value = member[other];
return value !== undefined && counts.get(value) === 1
? [[value, index] as const]
: [];
}),
);
for (const [value, index] of indexes) if (index === -1) indexes.delete(value);
return indexes;
};
/**