diff options
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/btree/map.rs | 8 | ||||
| -rw-r--r-- | src/liballoc/btree/node.rs | 13 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/liballoc/btree/map.rs b/src/liballoc/btree/map.rs index 985a41722d7..a88631b1e67 100644 --- a/src/liballoc/btree/map.rs +++ b/src/liballoc/btree/map.rs @@ -686,10 +686,6 @@ impl<K: Ord, V> BTreeMap<K, V> { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(&mut self, key: K, value: V) -> Option<V> { - if self.root.is_shared_root() { - self.root = node::Root::new_leaf(); - } - match self.entry(key) { Occupied(mut entry) => Some(entry.insert(value)), Vacant(entry) => { @@ -1301,6 +1297,10 @@ impl<K, V> Drop for IntoIter<K, V> { self.for_each(drop); unsafe { let leaf_node = ptr::read(&self.front).into_node(); + if leaf_node.is_shared_root() { + return; + } + if let Some(first_parent) = leaf_node.deallocate_and_ascend() { let mut cur_node = first_parent.into_node(); while let Some(parent) = cur_node.deallocate_and_ascend() { diff --git a/src/liballoc/btree/node.rs b/src/liballoc/btree/node.rs index 6381006e7fc..79615e11c67 100644 --- a/src/liballoc/btree/node.rs +++ b/src/liballoc/btree/node.rs @@ -101,6 +101,10 @@ impl<K, V> LeafNode<K, V> { len: 0 } } + + fn is_shared_root(&self) -> bool { + self as *const _ == &EMPTY_ROOT_NODE as *const _ as *const LeafNode<K, V> + } } // We need to implement Sync here in order to make a static instance @@ -185,10 +189,7 @@ unsafe impl<K: Send, V: Send> Send for Root<K, V> { } impl<K, V> Root<K, V> { pub fn is_shared_root(&self) -> bool { - ptr::eq( - self.node.as_ptr().as_ptr(), - &EMPTY_ROOT_NODE as *const _ as *const LeafNode<K, V>, - ) + self.as_ref().is_shared_root() } pub fn shared_empty_root() -> Self { @@ -387,6 +388,10 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> { } } + pub fn is_shared_root(&self) -> bool { + self.as_leaf().is_shared_root() + } + pub fn keys(&self) -> &[K] { self.reborrow().into_slices().0 } |
