Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
macladson committed Aug 30, 2023
1 parent f93c3c7 commit 1f8a9d7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ impl<T: Value + Send + Sync> Tree<T> {
let mut write_lock = RwLockUpgradableReadGuard::upgrade(read_lock);
let existing_hash = *write_lock;

// This second check is necessary in the case where another thread has
// This second check is necessary in the case where another thread has
// computed the hash while we were waiting to acquire the write lock.
if !existing_hash.is_zero() {
existing_hash
Expand All @@ -571,16 +571,18 @@ impl<T: Value + Send + Sync> Tree<T> {
let mut write_lock = RwLockUpgradableReadGuard::upgrade(read_lock);
let existing_hash = *write_lock;

// This second check is necessary in the case where another thread has
// This second check is necessary in the case where another thread has
// computed the hash while we were waiting to acquire the write lock.
if !existing_hash.is_zero() {
existing_hash
} else {
// Parallelism goes brrrr.
let (left_hash, right_hash) =
rayon::join(|| left.tree_hash(), || right.tree_hash());
let tree_hash =
Hash256::from(hash32_concat(left_hash.as_bytes(), right_hash.as_bytes()));
let tree_hash = Hash256::from(hash32_concat(
left_hash.as_bytes(),
right_hash.as_bytes(),
));
*write_lock = tree_hash;
tree_hash
}
Expand Down

0 comments on commit 1f8a9d7

Please sign in to comment.