mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Kill placement_new
This commit is contained in:
parent
f0231f7c1b
commit
0b5e890061
3 changed files with 3 additions and 104 deletions
|
@ -18,8 +18,7 @@ use fmt::{self, Debug};
|
||||||
use hash::{Hash, BuildHasher};
|
use hash::{Hash, BuildHasher};
|
||||||
use iter::{FromIterator, FusedIterator};
|
use iter::{FromIterator, FusedIterator};
|
||||||
use mem::{self, replace};
|
use mem::{self, replace};
|
||||||
use ops::{Deref, Index, InPlace, Place, Placer};
|
use ops::{Deref, Index};
|
||||||
use ptr;
|
|
||||||
|
|
||||||
use super::table::{self, Bucket, EmptyBucket, FullBucket, FullBucketMut, RawTable, SafeHash};
|
use super::table::{self, Bucket, EmptyBucket, FullBucket, FullBucketMut, RawTable, SafeHash};
|
||||||
use super::table::BucketState::{Empty, Full};
|
use super::table::BucketState::{Empty, Full};
|
||||||
|
@ -1777,61 +1776,7 @@ impl<'a, K, V> fmt::Debug for Drain<'a, K, V>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A place for insertion to a `Entry`.
|
// FORK NOTE: Removed Placer impl
|
||||||
///
|
|
||||||
/// See [`HashMap::entry`](struct.HashMap.html#method.entry) for details.
|
|
||||||
#[must_use = "places do nothing unless written to with `<-` syntax"]
|
|
||||||
pub struct EntryPlace<'a, K: 'a, V: 'a> {
|
|
||||||
bucket: FullBucketMut<'a, K, V>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for EntryPlace<'a, K, V> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
f.debug_struct("EntryPlace")
|
|
||||||
.field("key", self.bucket.read().0)
|
|
||||||
.field("value", self.bucket.read().1)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, K, V> Drop for EntryPlace<'a, K, V> {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
// Inplacement insertion failed. Only key need to drop.
|
|
||||||
// The value is failed to insert into map.
|
|
||||||
unsafe { self.bucket.remove_key() };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, K, V> Placer<V> for Entry<'a, K, V> {
|
|
||||||
type Place = EntryPlace<'a, K, V>;
|
|
||||||
|
|
||||||
fn make_place(self) -> EntryPlace<'a, K, V> {
|
|
||||||
let b = match self {
|
|
||||||
Occupied(mut o) => {
|
|
||||||
unsafe { ptr::drop_in_place(o.elem.read_mut().1); }
|
|
||||||
o.elem
|
|
||||||
}
|
|
||||||
Vacant(v) => {
|
|
||||||
unsafe { v.insert_key() }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
EntryPlace { bucket: b }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, K, V> Place<V> for EntryPlace<'a, K, V> {
|
|
||||||
fn pointer(&mut self) -> *mut V {
|
|
||||||
self.bucket.read_mut().1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, K, V> InPlace<V> for EntryPlace<'a, K, V> {
|
|
||||||
type Owner = ();
|
|
||||||
|
|
||||||
unsafe fn finalize(self) {
|
|
||||||
mem::forget(self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, K, V> Entry<'a, K, V> {
|
impl<'a, K, V> Entry<'a, K, V> {
|
||||||
/// Ensures a value is in the entry by inserting the default if empty, and returns
|
/// Ensures a value is in the entry by inserting the default if empty, and returns
|
||||||
|
@ -2119,26 +2064,6 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
|
||||||
};
|
};
|
||||||
b.into_mut_refs().1
|
b.into_mut_refs().1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only used for InPlacement insert. Avoid unnecessary value copy.
|
|
||||||
// The value remains uninitialized.
|
|
||||||
unsafe fn insert_key(self) -> FullBucketMut<'a, K, V> {
|
|
||||||
match self.elem {
|
|
||||||
NeqElem(mut bucket, disp) => {
|
|
||||||
if disp >= DISPLACEMENT_THRESHOLD {
|
|
||||||
bucket.table_mut().set_tag(true);
|
|
||||||
}
|
|
||||||
let uninit = mem::uninitialized();
|
|
||||||
robin_hood(bucket, disp, self.hash, self.key, uninit)
|
|
||||||
},
|
|
||||||
NoElem(mut bucket, disp) => {
|
|
||||||
if disp >= DISPLACEMENT_THRESHOLD {
|
|
||||||
bucket.table_mut().set_tag(true);
|
|
||||||
}
|
|
||||||
bucket.put_key(self.hash, self.key)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
|
impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
|
||||||
|
|
|
@ -487,21 +487,6 @@ impl<K, V, M> EmptyBucket<K, V, M>
|
||||||
table: self.table,
|
table: self.table,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Puts given key, remain value uninitialized.
|
|
||||||
/// It is only used for inplacement insertion.
|
|
||||||
pub unsafe fn put_key(mut self, hash: SafeHash, key: K) -> FullBucket<K, V, M> {
|
|
||||||
*self.raw.hash() = hash.inspect();
|
|
||||||
let pair_ptr = self.raw.pair();
|
|
||||||
ptr::write(&mut (*pair_ptr).0, key);
|
|
||||||
|
|
||||||
self.table.borrow_table_mut().size += 1;
|
|
||||||
|
|
||||||
FullBucket {
|
|
||||||
raw: self.raw,
|
|
||||||
table: self.table,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K, V, M: Deref<Target = RawTable<K, V>>> FullBucket<K, V, M> {
|
impl<K, V, M: Deref<Target = RawTable<K, V>>> FullBucket<K, V, M> {
|
||||||
|
@ -577,17 +562,6 @@ impl<'t, K, V> FullBucket<K, V, &'t mut RawTable<K, V>> {
|
||||||
v)
|
v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove this bucket's `key` from the hashtable.
|
|
||||||
/// Only used for inplacement insertion.
|
|
||||||
/// NOTE: `Value` is uninitialized when this function is called, don't try to drop the `Value`.
|
|
||||||
pub unsafe fn remove_key(&mut self) {
|
|
||||||
self.table.size -= 1;
|
|
||||||
|
|
||||||
*self.raw.hash() = EMPTY_BUCKET;
|
|
||||||
let pair_ptr = self.raw.pair();
|
|
||||||
ptr::drop_in_place(&mut (*pair_ptr).0); // only drop key
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This use of `Put` is misleading and restrictive, but safe and sufficient for our use cases
|
// This use of `Put` is misleading and restrictive, but safe and sufficient for our use cases
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![feature(allocator_api)]
|
#![feature(allocator_api)]
|
||||||
#![feature(alloc, shared, unique, fused, placement_new_protocol)]
|
#![feature(alloc, shared, unique, fused)]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue