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.
This commit is contained in:
Guy Pursey
2023-10-13 08:31:33 +01:00
parent 9f8457d249
commit 461a293d71

View File

@@ -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