From e476321818cace47e6c0d409660fb13663c9ccbf Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Tue, 16 Jun 2020 13:18:59 -0400 Subject: [PATCH] Use loops instead of functions in actionDisconnect.connections, for performance (re: #7706) --- modules/actions/disconnect.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/actions/disconnect.js b/modules/actions/disconnect.js index 95a9250c0..433ea8ed1 100644 --- a/modules/actions/disconnect.js +++ b/modules/actions/disconnect.js @@ -48,25 +48,31 @@ export function actionDisconnect(nodeId, newNodeId) { var candidates = []; var keeping = false; var parentWays = graph.parentWays(graph.entity(nodeId)); - - parentWays.forEach(function(way) { + var way, waynode; + for (var i = 0; i < parentWays.length; i++) { + way = parentWays[i]; if (wayIds && wayIds.indexOf(way.id) === -1) { keeping = true; - return; + continue; } if (way.isArea() && (way.nodes[0] === nodeId)) { candidates.push({ wayID: way.id, index: 0 }); } else { - way.nodes.forEach(function(waynode, index) { + for (var j = 0; j < way.nodes.length; j++) { + waynode = way.nodes[j]; if (waynode === nodeId) { - if (way.isClosed() && parentWays.length > 1 && wayIds && wayIds.indexOf(way.id) !== -1 && index === way.nodes.length-1) { - return; + if (way.isClosed() && + parentWays.length > 1 && + wayIds && + wayIds.indexOf(way.id) !== -1 && + j === way.nodes.length - 1) { + continue; } - candidates.push({ wayID: way.id, index: index }); + candidates.push({ wayID: way.id, index: j }); } - }); + } } - }); + } return keeping ? candidates : candidates.slice(1); };