Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 81b0c05

Browse files
committedOct 19, 2018
Auto merge of #55114 - oli-obk:fx#map, r=nikomatsakis
Deprecate the `FxHashMap()` and `FxHashSet()` constructor function hack
2 parents 74ff7dc + 53e92f4 commit 81b0c05

File tree

133 files changed

+428
-558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+428
-558
lines changed
 

‎src/bootstrap/cache.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,21 @@ impl Ord for Interned<String> {
169169
}
170170
}
171171

172-
struct TyIntern<T> {
172+
struct TyIntern<T: Hash + Clone + Eq> {
173173
items: Vec<T>,
174174
set: HashMap<T, Interned<T>>,
175175
}
176176

177-
impl<T: Hash + Clone + Eq> TyIntern<T> {
178-
fn new() -> TyIntern<T> {
177+
impl<T: Hash + Clone + Eq> Default for TyIntern<T> {
178+
fn default() -> Self {
179179
TyIntern {
180180
items: Vec::new(),
181-
set: HashMap::new(),
181+
set: Default::default(),
182182
}
183183
}
184+
}
184185

186+
impl<T: Hash + Clone + Eq> TyIntern<T> {
185187
fn intern_borrow<B>(&mut self, item: &B) -> Interned<T>
186188
where
187189
B: Eq + Hash + ToOwned<Owned=T> + ?Sized,
@@ -212,19 +214,13 @@ impl<T: Hash + Clone + Eq> TyIntern<T> {
212214
}
213215
}
214216

217+
#[derive(Default)]
215218
pub struct Interner {
216219
strs: Mutex<TyIntern<String>>,
217220
paths: Mutex<TyIntern<PathBuf>>,
218221
}
219222

220223
impl Interner {
221-
fn new() -> Interner {
222-
Interner {
223-
strs: Mutex::new(TyIntern::new()),
224-
paths: Mutex::new(TyIntern::new()),
225-
}
226-
}
227-
228224
pub fn intern_str(&self, s: &str) -> Interned<String> {
229225
self.strs.lock().unwrap().intern_borrow(s)
230226
}
@@ -238,7 +234,7 @@ impl Interner {
238234
}
239235

240236
lazy_static! {
241-
pub static ref INTERNER: Interner = Interner::new();
237+
pub static ref INTERNER: Interner = Interner::default();
242238
}
243239

244240
/// This is essentially a HashMap which allows storing any type in its input and

‎src/libarena/lib.rs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ impl<T> TypedArenaChunk<T> {
114114

115115
const PAGE: usize = 4096;
116116

117-
impl<T> TypedArena<T> {
117+
impl<T> Default for TypedArena<T> {
118118
/// Creates a new `TypedArena`.
119-
#[inline]
120-
pub fn new() -> TypedArena<T> {
119+
fn default() -> TypedArena<T> {
121120
TypedArena {
122121
// We set both `ptr` and `end` to 0 so that the first call to
123122
// alloc() will trigger a grow().
@@ -127,7 +126,9 @@ impl<T> TypedArena<T> {
127126
_own: PhantomData,
128127
}
129128
}
129+
}
130130

131+
impl<T> TypedArena<T> {
131132
/// Allocates an object in the `TypedArena`, returning a reference to it.
132133
#[inline]
133134
pub fn alloc(&self, object: T) -> &mut T {
@@ -296,15 +297,17 @@ pub struct DroplessArena {
296297

297298
unsafe impl Send for DroplessArena {}
298299

299-
impl DroplessArena {
300-
pub fn new() -> DroplessArena {
300+
impl Default for DroplessArena {
301+
fn default() -> DroplessArena {
301302
DroplessArena {
302303
ptr: Cell::new(0 as *mut u8),
303304
end: Cell::new(0 as *mut u8),
304-
chunks: RefCell::new(vec![]),
305+
chunks: Default::default(),
305306
}
306307
}
308+
}
307309

310+
impl DroplessArena {
308311
pub fn in_arena<T: ?Sized>(&self, ptr: *const T) -> bool {
309312
let ptr = ptr as *const u8 as *mut u8;
310313
for chunk in &*self.chunks.borrow() {
@@ -419,18 +422,13 @@ impl DroplessArena {
419422
}
420423
}
421424

425+
#[derive(Default)]
426+
// FIXME(@Zoxc): this type is entirely unused in rustc
422427
pub struct SyncTypedArena<T> {
423428
lock: MTLock<TypedArena<T>>,
424429
}
425430

426431
impl<T> SyncTypedArena<T> {
427-
#[inline(always)]
428-
pub fn new() -> SyncTypedArena<T> {
429-
SyncTypedArena {
430-
lock: MTLock::new(TypedArena::new())
431-
}
432-
}
433-
434432
#[inline(always)]
435433
pub fn alloc(&self, object: T) -> &mut T {
436434
// Extend the lifetime of the result since it's limited to the lock guard
@@ -452,18 +450,12 @@ impl<T> SyncTypedArena<T> {
452450
}
453451
}
454452

453+
#[derive(Default)]
455454
pub struct SyncDroplessArena {
456455
lock: MTLock<DroplessArena>,
457456
}
458457

459458
impl SyncDroplessArena {
460-
#[inline(always)]
461-
pub fn new() -> SyncDroplessArena {
462-
SyncDroplessArena {
463-
lock: MTLock::new(DroplessArena::new())
464-
}
465-
}
466-
467459
#[inline(always)]
468460
pub fn in_arena<T: ?Sized>(&self, ptr: *const T) -> bool {
469461
self.lock.lock().in_arena(ptr)
@@ -508,7 +500,7 @@ mod tests {
508500

509501
#[test]
510502
pub fn test_unused() {
511-
let arena: TypedArena<Point> = TypedArena::new();
503+
let arena: TypedArena<Point> = TypedArena::default();
512504
assert!(arena.chunks.borrow().is_empty());
513505
}
514506

@@ -546,7 +538,7 @@ mod tests {
546538
}
547539
}
548540

549-
let arena = Wrap(TypedArena::new());
541+
let arena = Wrap(TypedArena::default());
550542

551543
let result = arena.alloc_outer(|| Outer {
552544
inner: arena.alloc_inner(|| Inner { value: 10 }),
@@ -557,15 +549,15 @@ mod tests {
557549

558550
#[test]
559551
pub fn test_copy() {
560-
let arena = TypedArena::new();
552+
let arena = TypedArena::default();
561553
for _ in 0..100000 {
562554
arena.alloc(Point { x: 1, y: 2, z: 3 });
563555
}
564556
}
565557

566558
#[bench]
567559
pub fn bench_copy(b: &mut Bencher) {
568-
let arena = TypedArena::new();
560+
let arena = TypedArena::default();
569561
b.iter(|| arena.alloc(Point { x: 1, y: 2, z: 3 }))
570562
}
571563

@@ -584,7 +576,7 @@ mod tests {
584576

585577
#[test]
586578
pub fn test_noncopy() {
587-
let arena = TypedArena::new();
579+
let arena = TypedArena::default();
588580
for _ in 0..100000 {
589581
arena.alloc(Noncopy {
590582
string: "hello world".to_string(),
@@ -595,15 +587,15 @@ mod tests {
595587

596588
#[test]
597589
pub fn test_typed_arena_zero_sized() {
598-
let arena = TypedArena::new();
590+
let arena = TypedArena::default();
599591
for _ in 0..100000 {
600592
arena.alloc(());
601593
}
602594
}
603595

604596
#[test]
605597
pub fn test_typed_arena_clear() {
606-
let mut arena = TypedArena::new();
598+
let mut arena = TypedArena::default();
607599
for _ in 0..10 {
608600
arena.clear();
609601
for _ in 0..10000 {
@@ -628,7 +620,7 @@ mod tests {
628620
fn test_typed_arena_drop_count() {
629621
let counter = Cell::new(0);
630622
{
631-
let arena: TypedArena<DropCounter> = TypedArena::new();
623+
let arena: TypedArena<DropCounter> = TypedArena::default();
632624
for _ in 0..100 {
633625
// Allocate something with drop glue to make sure it doesn't leak.
634626
arena.alloc(DropCounter { count: &counter });
@@ -640,7 +632,7 @@ mod tests {
640632
#[test]
641633
fn test_typed_arena_drop_on_clear() {
642634
let counter = Cell::new(0);
643-
let mut arena: TypedArena<DropCounter> = TypedArena::new();
635+
let mut arena: TypedArena<DropCounter> = TypedArena::default();
644636
for i in 0..10 {
645637
for _ in 0..100 {
646638
// Allocate something with drop glue to make sure it doesn't leak.
@@ -667,7 +659,7 @@ mod tests {
667659
fn test_typed_arena_drop_small_count() {
668660
DROP_COUNTER.with(|c| c.set(0));
669661
{
670-
let arena: TypedArena<SmallDroppable> = TypedArena::new();
662+
let arena: TypedArena<SmallDroppable> = TypedArena::default();
671663
for _ in 0..100 {
672664
// Allocate something with drop glue to make sure it doesn't leak.
673665
arena.alloc(SmallDroppable);
@@ -679,7 +671,7 @@ mod tests {
679671

680672
#[bench]
681673
pub fn bench_noncopy(b: &mut Bencher) {
682-
let arena = TypedArena::new();
674+
let arena = TypedArena::default();
683675
b.iter(|| {
684676
arena.alloc(Noncopy {
685677
string: "hello world".to_string(),

0 commit comments

Comments
 (0)
Please sign in to comment.