Skip to content

Commit 627837f

Browse files
committed
f.
1 parent 745229b commit 627837f

File tree

1 file changed

+16
-36
lines changed

1 file changed

+16
-36
lines changed

Diff for: src/libstd/collections/hash/table.rs

+16-36
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,15 @@ struct RawBucket<K, V> {
7777
kval: *mut (K, V),
7878
}
7979

80-
impl<K, V> Copy for RawBucket<K, V> {}
81-
82-
#[derive(Clone)]
83-
pub struct TableRef<M>(pub M);
84-
85-
impl<M: Copy> Copy for TableRef<M> {}
86-
8780
pub struct Bucket<K, V, M, S = ()> {
8881
raw: RawBucket<K, V>,
8982
idx: usize,
9083
capacity: usize,
91-
table: TableRef<M>,
84+
table: M,
9285
}
9386

87+
impl<K, V> Copy for RawBucket<K, V> {}
88+
9489
impl<K, V, M: Copy, S> Copy for Bucket<K,V,M,S> where M: Borrow<RawTable<K, V>> {}
9590

9691
mod bucket {
@@ -170,20 +165,6 @@ fn can_alias_safehash_as_option() {
170165
assert_eq!(size_of::<SafeHash>(), size_of::<Option<SafeHash>>())
171166
}
172167

173-
impl<K, V, M> Deref for TableRef<M> where M: Borrow<RawTable<K, V>> {
174-
type Target = RawTable<K, V>;
175-
176-
fn deref(&self) -> &RawTable<K, V> {
177-
self.0.borrow()
178-
}
179-
}
180-
181-
impl<K, V, M> DerefMut for TableRef<M> where M: Borrow<RawTable<K, V>> {
182-
fn deref_mut(&mut self) -> &mut RawTable<K, V> {
183-
self.0.borrow_mut()
184-
}
185-
}
186-
187168
impl<K, V> RawBucket<K, V> {
188169
unsafe fn offset(self, count: isize) -> RawBucket<K, V> {
189170
RawBucket {
@@ -199,15 +180,15 @@ impl<K, V, M, S> Borrow<RawTable<K, V>> for Bucket<K, V, M, S>
199180
where M: Borrow<RawTable<K, V>>
200181
{
201182
fn borrow(&self) -> &RawTable<K, V> {
202-
self.table.0.borrow()
183+
self.table.borrow()
203184
}
204185
}
205186

206187
impl<K, V, M, S> BorrowMut<RawTable<K, V>> for Bucket<K, V, M, S>
207188
where M: Borrow<RawTable<K, V>>
208189
{
209190
fn borrow_mut(&mut self) -> &mut RawTable<K, V> {
210-
self.table.0.borrow_mut()
191+
self.table.borrow_mut()
211192
}
212193
}
213194

@@ -221,11 +202,11 @@ impl<K, V, M: Put> Put for FullBucket<K, V, M> {}
221202
impl<K, V, M, S> Bucket<K, V, M, S> {
222203
/// Borrow a reference to the table.
223204
pub fn table(&self) -> &M {
224-
&self.table.0
205+
&self.table
225206
}
226207
/// Move out the reference to the table.
227208
pub fn into_table(self) -> M {
228-
self.table.0
209+
self.table
229210
}
230211
/// Get the raw index.
231212
pub fn index(&self) -> usize {
@@ -251,11 +232,10 @@ impl<K, V, M> Bucket<K, V, M> where M: Borrow<RawTable<K, V>> {
251232
pub fn at_index(table: M, ib_index: uint)
252233
-> Result<Bucket<K, V, M>, Bucket<K, V, M, bucket::TableIsEmpty>>
253234
{
254-
let table = TableRef(table);
255-
let capacity = table.capacity();
235+
let capacity = table.borrow().capacity();
256236
let idx = ib_index & (capacity - 1);
257237
let bucket: Bucket<K, V, M> = Bucket {
258-
raw: unsafe { table.first_bucket_raw().offset(idx as isize) },
238+
raw: unsafe { table.borrow().first_bucket_raw().offset(idx as isize) },
259239
idx: idx,
260240
capacity: capacity,
261241
table: table,
@@ -273,7 +253,7 @@ impl<K, V, M> Bucket<K, V, M> where M: Borrow<RawTable<K, V>> {
273253

274254
/// Narrows down the range of iteration, which must be a power of 2.
275255
pub fn iter_to(mut self, limit: usize) -> Bucket<K, V, M> {
276-
assert!(limit <= self.table.capacity());
256+
assert!(limit <= self.table.borrow().capacity());
277257
assert!(limit.is_power_of_two());
278258
self.capacity = limit;
279259
self
@@ -334,15 +314,15 @@ impl<K, V, M, S> Bucket<K, V, M, S> where M: Borrow<RawTable<K, V>> {
334314
raw: self.raw,
335315
idx: self.idx,
336316
capacity: self.capacity,
337-
table: TableRef(self),
317+
table: self,
338318
}
339319
}
340320
}
341321

342322
impl<K, V, M> EmptyBucket<K, V, M> where M: Borrow<RawTable<K, V>> {
343323
pub fn gap_peek(self) -> Option<GapThenFull<K, V, M>> {
344324
let gap = Bucket {
345-
table: TableRef(()),
325+
table: (),
346326
idx: self.idx,
347327
capacity: self.capacity,
348328
raw: self.raw,
@@ -360,7 +340,7 @@ impl<K, V, M> EmptyBucket<K, V, M> where M: Borrow<RawTable<K, V>> {
360340
}
361341
}
362342

363-
impl<K, V, M> EmptyBucket<K, V, M> where M: Borrow<RawTable<K, V>>, M: Put {
343+
impl<K, V, M> EmptyBucket<K, V, M> where M: BorrowMut<RawTable<K, V>>, M: Put {
364344
/// Puts given key and value pair, along with the key's hash,
365345
/// into this bucket in the hashtable. Note how `self` is 'moved' into
366346
/// this function, because this slot will no longer be empty when
@@ -375,7 +355,7 @@ impl<K, V, M> EmptyBucket<K, V, M> where M: Borrow<RawTable<K, V>>, M: Put {
375355
ptr::write(self.raw.kval, (key, value));
376356
}
377357

378-
self.table.size += 1;
358+
self.table.borrow_mut().size += 1;
379359

380360
self.unsafe_cast()
381361
}
@@ -432,7 +412,7 @@ impl<'t, K, V, M: 't> FullBucket<K, V, M> where M: BorrowMut<RawTable<K, V>> {
432412
/// This works similarly to `put`, building an `EmptyBucket` out of the
433413
/// taken bucket.
434414
pub fn take(mut self) -> (EmptyBucket<K, V, M>, K, V) {
435-
self.table.size -= 1;
415+
self.table.borrow_mut().size -= 1;
436416

437417
unsafe {
438418
*self.raw.hash = None;
@@ -637,7 +617,7 @@ impl<'t, K, V, M: 't> RawFullBucket<K, V, M> where M: BorrowMut<RawTable<K, V>>
637617
pub struct RawFullBuckets<K, V, M> {
638618
raw: RawBucket<K, V>,
639619
hashes_end: *mut Option<SafeHash>,
640-
table: TableRef<M>,
620+
table: M,
641621
}
642622

643623
// FIXME(#19839) Remove in favor of `#[derive(Clone)]`

0 commit comments

Comments
 (0)