Skip to content

Commit

Permalink
Optimize duplicate parent detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Mar 7, 2024
1 parent 3b6009b commit 88a972c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/inscriptions/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,19 @@ impl Inscription {
}

pub(crate) fn parents(&self) -> Vec<InscriptionId> {
let mut parents: Vec<InscriptionId> = self
let mut unique_parents: HashSet<Vec<u8>> = HashSet::with_capacity(self.parents.len());
self
.parents
.iter()
.map(|p| {
if !unique_parents.insert(p.clone()) {
return None;
}
// the option detour is a bit awkward
Self::inscription_id_field(&Some(p.clone()))
})
.flatten()
.collect();

// remove duplicates
let mut uniques: HashSet<InscriptionId> = HashSet::with_capacity(self.parents.len());
parents.retain(|p| uniques.insert(p.clone()));

parents
.collect()
}

pub(crate) fn pointer(&self) -> Option<u64> {
Expand Down

0 comments on commit 88a972c

Please sign in to comment.