Skip to content

Commit b05ec33

Browse files
committed
Use useMemo for 'nameSet'
1 parent 1d2c2cf commit b05ec33

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

extensions/ql-vscode/src/view/compare-performance/ComparePerformance.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ChangeEvent } from "react";
2-
import { useMemo, useState, Fragment } from "react";
2+
import { Fragment, useMemo, useState } from "react";
33
import type {
44
SetPerformanceComparisonQueries,
55
ToComparePerformanceViewMessage,
@@ -354,6 +354,14 @@ function withToggledValue<T>(set: Set<T>, value: T) {
354354
return result;
355355
}
356356

357+
function union<T>(a: Set<T> | T[], b: Set<T> | T[]) {
358+
const result = new Set(a);
359+
for (const x of b) {
360+
result.add(x);
361+
}
362+
return result;
363+
}
364+
357365
export function ComparePerformance(_: Record<string, never>) {
358366
const [data, setData] = useState<
359367
SetPerformanceComparisonQueries | undefined
@@ -398,10 +406,10 @@ function ComparePerformanceWithData(props: {
398406

399407
const [metric, setMetric] = useState<Metric>(metrics.tuples);
400408

401-
const nameSet = new Set(from.data.names);
402-
for (const name of to.data.names) {
403-
nameSet.add(name);
404-
}
409+
const nameSet = useMemo(
410+
() => union(from.data.names, to.data.names),
411+
[from, to],
412+
);
405413

406414
let hasCacheHitMismatch = false;
407415

0 commit comments

Comments
 (0)