perf: reduce chained array traversal

This commit is contained in:
2026-06-05 18:27:08 +08:00
parent d09e5e673e
commit 0d136d8622
4 changed files with 50 additions and 10 deletions
+10 -5
View File
@@ -82,11 +82,16 @@ export function useCanvasNodeDrag(params: UseCanvasNodeDragParams) {
const cy = pos.y + size.height / 2;
const right = pos.x + size.width;
const bottom = pos.y + size.height;
const others = [
...textNodesRef.current.filter((n) => n.id !== draggedId).map((n) => ({ pos: n.position, size: n.size })),
...imageNodesRef.current.filter((n) => n.id !== draggedId).map((n) => ({ pos: n.position, size: n.size })),
...videoNodesRef.current.filter((n) => n.id !== draggedId).map((n) => ({ pos: n.position, size: n.size })),
];
const others: Array<{ pos: CanvasPoint; size: CanvasNodeSize }> = [];
for (const node of textNodesRef.current) {
if (node.id !== draggedId) others.push({ pos: node.position, size: node.size });
}
for (const node of imageNodesRef.current) {
if (node.id !== draggedId) others.push({ pos: node.position, size: node.size });
}
for (const node of videoNodesRef.current) {
if (node.id !== draggedId) others.push({ pos: node.position, size: node.size });
}
for (const other of others) {
const ocx = other.pos.x + other.size.width / 2;
const ocy = other.pos.y + other.size.height / 2;