From 461a293d71500610299e823769624708b7986cda Mon Sep 17 00:00:00 2001 From: Guy Pursey Date: Fri, 13 Oct 2023 08:31:33 +0100 Subject: [PATCH] GitGraph: refactored overlapping fn for efficiency/performance On previous rewrite, I had created new functions within the overlapping functions but these were being recreated on each iteration of Object.some(). I moved them outside this for clarity and so they're not recreated each iteration. --- .../mermaid/src/diagrams/git/gitGraphRenderer.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js index 2c737ec10..3d5be94a8 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js +++ b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js @@ -351,17 +351,18 @@ const drawCommits = (svg, commits, modifyGraph) => { * commitA's x-position * and commitB's x-position */ -const hasOverlappingCommits = (commitA, commitB, allCommits) => - Object.values(allCommits).some((commitX) => { - const isOnSourceBranch = (x) => x.branch === commitA.branch; - const isOnTargetBranch = (x) => x.branch === commitB.branch; - const isBetweenCommits = (x) => x.seq > commitA.seq && x.seq < commitB.seq; - const isTargetMain = (x) => x.branch === getConfig().gitGraph.mainBranchName; +const hasOverlappingCommits = (commitA, commitB, allCommits) => { + const isOnSourceBranch = (x) => x.branch === commitA.branch; + const isOnTargetBranch = (x) => x.branch === commitB.branch; + const isBetweenCommits = (x) => x.seq > commitA.seq && x.seq < commitB.seq; + const isTargetMain = (x) => x.branch === getConfig().gitGraph.mainBranchName; + return Object.values(allCommits).some((commitX) => { return ( (isOnSourceBranch(commitX) || (isOnTargetBranch(commitX) && !isTargetMain(commitX))) && isBetweenCommits(commitX) ); }); +}; /** * This function find a lane in the y-axis that is not overlapping with any other lanes. This is