Skip to content

Commit b2f5a5e

Browse files
authored
Merge pull request #422 from dizer-ti/main
optimize nodeInfo::quorum() by returning reference instead of cloning
2 parents 8bc6758 + ba85de4 commit b2f5a5e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

sailfish-consensus/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ where
974974
}
975975
actions.push(Action::Catchup(Round::new(r, self.committee.id())));
976976
}
977-
} else if self.committed_round >= self.nodes.quorum() {
977+
} else if self.committed_round >= *self.nodes.quorum() {
978978
for v in self.buffer.drain_round(r) {
979979
self.dag.add(v)
980980
}

sailfish-types/src/nodeinfo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub struct NodeInfo<T> {
66
quorum: usize,
77
}
88

9-
impl<T: Default + PartialOrd + Clone> NodeInfo<T> {
9+
impl<T: Default + PartialOrd> NodeInfo<T> {
1010
pub fn new(c: &Committee) -> Self {
1111
Self {
1212
nodes: c.parties().map(|k| (*k, T::default())).collect(),
@@ -43,8 +43,8 @@ impl<T: Default + PartialOrd + Clone> NodeInfo<T> {
4343
}
4444

4545
/// Gets the lower bound of the highest quorum interval.
46-
pub fn quorum(&self) -> T {
46+
pub fn quorum(&self) -> &T {
4747
debug_assert!(self.quorum <= self.nodes.len());
48-
self.nodes[self.quorum - 1].1.clone()
48+
&self.nodes[self.quorum - 1].1
4949
}
5050
}

0 commit comments

Comments
 (0)