Skip to content

Commit 46ea6cc

Browse files
committed
refactor: Simplify branch column assignment
Change content of group_offset to include offset 0 at index 0. Convert code from functional to imperative.
1 parent 5ec1159 commit 46ea6cc

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/graph.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -898,21 +898,21 @@ fn assign_branch_columns(
898898
group_occ[found].push((start, end));
899899
}
900900

901-
let group_offset: Vec<usize> = occupied
902-
.iter()
903-
.scan(0, |acc, group| {
904-
*acc += group.len();
905-
Some(*acc)
906-
})
907-
.collect();
901+
// Compute start column of each group
902+
let mut group_offset: Vec<usize> = vec![];
903+
let mut acc = 0;
904+
for group in occupied {
905+
group_offset.push(acc);
906+
acc += group.len();
907+
}
908908

909+
// Compute branch column. Up till now we have computed the branch group
910+
// and the column offset within that group. This was to make it easy to
911+
// insert columns between groups. Now it is time to convert offset relative
912+
// to the group the final column.
909913
for branch in branches {
910914
if let Some(column) = branch.visual.column {
911-
let offset = if branch.visual.order_group == 0 {
912-
0
913-
} else {
914-
group_offset[branch.visual.order_group - 1]
915-
};
915+
let offset = group_offset[branch.visual.order_group];
916916
branch.visual.column = Some(column + offset);
917917
}
918918
}

0 commit comments

Comments
 (0)