Skip to content

Commit

Permalink
remove dead code from bincode deserialize of EncodedNode (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Laine authored Feb 28, 2024
1 parent 9b49f69 commit 983765c
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions firewood/src/merkle/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ impl<'de> Deserialize<'de> for EncodedNode<Bincode> {
.map_err(D::Error::custom)?;
let path = PartialPath::from_nibbles(Nibbles::<0>::new(&path).into_iter()).0;

let mut value = items
let value = items
.pop()
.unwrap_or_default()
.deserialize::<Bincode>()
Expand All @@ -747,26 +747,13 @@ impl<'de> Deserialize<'de> for EncodedNode<Bincode> {
let mut children: [Option<Vec<u8>>; BranchNode::MAX_CHILDREN] = Default::default();

for (i, chd) in items.into_iter().enumerate() {
if i == len - 1 {
let data = match chd {
Encoded::Raw(data) => Err(D::Error::custom(format!(
"incorrect encoded type for branch node value {:?}",
data
)))?,
Encoded::Data(data) => Bincode::deserialize(data.as_ref())
.map_err(|e| D::Error::custom(format!("bincode error: {e}")))?,
};
// Extract the value of the branch node and set to None if it's an empty Vec
value = Some(Data(data)).filter(|data| !data.is_empty());
} else {
let chd = match chd {
Encoded::Raw(chd) => chd,
Encoded::Data(chd) => Bincode::deserialize(chd.as_ref())
.map_err(|e| D::Error::custom(format!("bincode error: {e}")))?,
};
#[allow(clippy::indexing_slicing)]
(children[i] = Some(chd).filter(|chd| !chd.is_empty()));
}
let chd = match chd {
Encoded::Raw(chd) => chd,
Encoded::Data(chd) => Bincode::deserialize(chd.as_ref())
.map_err(|e| D::Error::custom(format!("bincode error: {e}")))?,
};
#[allow(clippy::indexing_slicing)]
(children[i] = Some(chd).filter(|chd| !chd.is_empty()));
}

let node = EncodedNodeType::Branch {
Expand Down

0 comments on commit 983765c

Please sign in to comment.