Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some stylistic improvements #130

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/iter/traverser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ impl<'g, K, V> Iterator for NodeIter<'g, K, V> {
BinEntry::TreeNode(ref tree_node) => {
e = Some(&tree_node.node);
}
BinEntry::Moved => unreachable!("Nodes can only point to Nodes or TreeNodes"),
BinEntry::Tree(_) => unreachable!("Nodes can only point to Nodes or TreeNodes"),
BinEntry::Moved | BinEntry::Tree(_) => {
unreachable!("Nodes can only point to Nodes or TreeNodes")
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1720,11 +1720,10 @@ where
Err(changed) => {
assert!(!changed.current.is_null());
bin = changed.current;
if let BinEntry::Node(node) = unsafe { changed.new.into_box() }.value {
key = node.key;
} else {
let BinEntry::Node(node) = unsafe { changed.new.into_box() }.value else {
unreachable!("we declared node and it is a BinEntry::Node");
}
};
key = node.key;
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,11 +949,10 @@ impl<K, V> TreeBin<K, V> {
Box::from_raw(ptr).value
};

if let BinEntry::Tree(mut tree_bin) = bin {
tree_bin.drop_fields(false);
} else {
let BinEntry::Tree(mut tree_bin) = bin else {
unreachable!("bin is a tree bin");
}
};
tree_bin.drop_fields(false);
});
}

Expand Down Expand Up @@ -988,16 +987,15 @@ impl<K, V> TreeBin<K, V> {
) {
let mut p = from;
while !p.is_null() {
if let BinEntry::TreeNode(tree_node) = p.into_box().value {
// if specified, drop the value in this node
if drop_values {
let _ = tree_node.node.value.into_box();
}
// then we move to the next node
p = tree_node.node.next.load(Ordering::SeqCst, guard);
} else {
let BinEntry::TreeNode(tree_node) = p.into_box().value else {
unreachable!("Trees can only ever contain TreeNodes");
};
// if specified, drop the value in this node
if drop_values {
let _ = tree_node.node.value.into_box();
}
// then we move to the next node
p = tree_node.node.next.load(Ordering::SeqCst, guard);
}
}
}
Expand Down
14 changes: 4 additions & 10 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ impl<K, V> Table<K, V> {
BinEntry::Node(_) => {
let mut node = bin;
loop {
let n = if let BinEntry::Node(ref n) = **node {
n
} else {
let BinEntry::Node(ref n) = **node else {
unreachable!("BinEntry::Node only points to BinEntry::Node");
};

Expand Down Expand Up @@ -209,9 +207,7 @@ impl<K, V> Table<K, V> {
// we replaced the bin with a NULL, so there's no future way to access it
// either; we own all the nodes in the list.

let node = if let BinEntry::Node(node) = p.value {
node
} else {
let BinEntry::Node(node) = p.value else {
unreachable!();
};

Expand All @@ -228,10 +224,8 @@ impl<K, V> Table<K, V> {
BinEntry::Tree(_) => {
// safety: same as for BinEntry::Node
let p = unsafe { bin.into_box() };
let bin = if let BinEntry::Tree(bin) = p.value {
bin
} else {
unreachable!();
let BinEntry::Tree(bin) = p.value else {
unreachable!()
};
// TreeBin::drop will take care of freeing the contained TreeNodes and their values
drop(bin);
Expand Down
Loading