perf: reduce chained array traversal
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user