Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Remove expect #8536

Merged
merged 4 commits into from
May 4, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove expect
dvdplm committed May 3, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8b5fc053e7a42666195064d75d6e05668b17bbc0
43 changes: 23 additions & 20 deletions util/patricia_trie/src/lookup.rs
Original file line number Diff line number Diff line change
@@ -55,29 +55,32 @@ impl<'a, Q: Query> Lookup<'a, Q> {
// without incrementing the depth.
let mut node_data = &node_data[..];
loop {
match Node::decoded(node_data).expect("rlp read from db; qed") {
Node::Leaf(slice, value) => {
return Ok(match slice == key {
true => Some(self.query.decode(value)),
false => None,
})
}
Node::Extension(slice, item) => {
if key.starts_with(&slice) {
node_data = item;
key = key.mid(slice.len());
} else {
return Ok(None)
match Node::decoded(node_data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this nested match could be avoided with a ? here and change the From impl to Box<TrieError>?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, totally works! :)

Ok(decoded_node) => match decoded_node {
Node::Leaf(slice, value) => {
return Ok(match slice == key {
true => Some(self.query.decode(value)),
false => None,
})
}
}
Node::Branch(children, value) => match key.is_empty() {
true => return Ok(value.map(move |val| self.query.decode(val))),
false => {
node_data = children[key.at(0) as usize];
key = key.mid(1);
Node::Extension(slice, item) => {
if key.starts_with(&slice) {
node_data = item;
key = key.mid(slice.len());
} else {
return Ok(None)
}
}
Node::Branch(children, value) => match key.is_empty() {
true => return Ok(value.map(move |val| self.query.decode(val))),
false => {
node_data = children[key.at(0) as usize];
key = key.mid(1);
}
},
_ => return Ok(None),
},
_ => return Ok(None),
_ => return Ok(None)
}

// check if new node data is inline or hash.