Avoid expensive cryptographic tree root recalculations in eq() (#7386)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
ca8d529a09
commit
67e3c26190
|
@ -428,7 +428,13 @@ impl Eq for NoteCommitmentTree {}
|
|||
|
||||
impl PartialEq for NoteCommitmentTree {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.hash() == other.hash()
|
||||
if let (Some(root), Some(other_root)) = (self.cached_root(), other.cached_root()) {
|
||||
// Use cached roots if available
|
||||
root == other_root
|
||||
} else {
|
||||
// Avoid expensive root recalculations which use multiple cryptographic hashes
|
||||
self.inner == other.inner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -423,7 +423,13 @@ impl Eq for NoteCommitmentTree {}
|
|||
|
||||
impl PartialEq for NoteCommitmentTree {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.hash() == other.hash()
|
||||
if let (Some(root), Some(other_root)) = (self.cached_root(), other.cached_root()) {
|
||||
// Use cached roots if available
|
||||
root == other_root
|
||||
} else {
|
||||
// Avoid expensive root recalculations which use multiple cryptographic hashes
|
||||
self.inner == other.inner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -377,7 +377,13 @@ impl Eq for NoteCommitmentTree {}
|
|||
|
||||
impl PartialEq for NoteCommitmentTree {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.hash() == other.hash()
|
||||
if let (Some(root), Some(other_root)) = (self.cached_root(), other.cached_root()) {
|
||||
// Use cached roots if available
|
||||
root == other_root
|
||||
} else {
|
||||
// Avoid expensive root recalculations which use multiple cryptographic hashes
|
||||
self.inner == other.inner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue