Skip to content

Commit

Permalink
chore: skip clone when tip < number
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Apr 23, 2023
1 parent 8ee72bd commit 087e742
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions sync/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,6 @@ impl HeaderView {
return;
}
self.skip_hash = self
.clone()
.get_ancestor(
tip_number,
get_skip_height(self.number()),
Expand All @@ -1041,7 +1040,7 @@ impl HeaderView {
}

pub fn get_ancestor<F, G>(
self,
&self,
tip_number: BlockNumber,
number: BlockNumber,
get_header_view: F,
Expand All @@ -1051,11 +1050,11 @@ impl HeaderView {
F: Fn(&Byte32, Option<bool>) -> Option<HeaderView>,
G: Fn(BlockNumber, BlockNumberAndHash) -> Option<HeaderView>,
{
let mut current = self;
if number > current.number() {
if number > self.number() {
return None;
}

let mut current = self.clone();
let mut number_walk = current.number();
while number_walk > number {
let number_skip = get_skip_height(number_walk);
Expand Down Expand Up @@ -1994,8 +1993,7 @@ impl ActiveChain {
|hash, store_first_opt| self.shared.get_header_view(hash, store_first_opt),
|number, current| {
// shortcut to return an ancestor block
if current.number <= tip_number && self.snapshot().is_main_chain(&current.hash)
{
if current.number <= tip_number && self.snapshot().is_main_chain(&current.hash) {
self.get_block_hash(number)
.and_then(|hash| self.shared.get_header_view(&hash, Some(true)))
} else {
Expand Down

0 comments on commit 087e742

Please sign in to comment.