Skip to content

Commit 2afec4d

Browse files
committed
Use FxHashSet instead of HashMap
1 parent d756f61 commit 2afec4d

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/librustc/ty/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub use self::IntVarValue::*;
1616
pub use self::LvaluePreference::*;
1717
pub use self::fold::TypeFoldable;
1818

19-
use std::collections::{hash_map, HashMap};
2019
use dep_graph::{self, DepNode};
2120
use hir::map as ast_map;
2221
use middle;
@@ -31,7 +30,7 @@ use ty::subst::{Subst, Substs};
3130
use ty::walk::TypeWalker;
3231
use util::common::MemoizationMap;
3332
use util::nodemap::NodeSet;
34-
use util::nodemap::FxHashMap;
33+
use util::nodemap::{FxHashMap, FxHashSet};
3534

3635
use serialize::{self, Encodable, Encoder};
3736
use std::borrow::Cow;
@@ -1393,13 +1392,12 @@ impl<'tcx> serialize::UseSpecializedDecodable for AdtDef<'tcx> {}
13931392
impl<'a, 'gcx, 'tcx> AdtDefData<'tcx, 'static> {
13941393
#[inline]
13951394
pub fn is_uninhabited_recurse(&'tcx self,
1396-
visited: &mut HashMap<(DefId, &'tcx Substs<'tcx>), ()>,
1395+
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
13971396
block: Option<NodeId>,
13981397
cx: TyCtxt<'a, 'gcx, 'tcx>,
13991398
substs: &'tcx Substs<'tcx>) -> bool {
1400-
match visited.entry((self.did, substs)) {
1401-
hash_map::Entry::Occupied(_) => return false,
1402-
hash_map::Entry::Vacant(ve) => ve.insert(()),
1399+
if !visited.insert((self.did, substs)) {
1400+
return false;
14031401
};
14041402
self.variants.iter().all(|v| {
14051403
v.is_uninhabited_recurse(visited, block, cx, substs, self.is_union())
@@ -1811,7 +1809,7 @@ impl<'tcx, 'container> VariantDefData<'tcx, 'container> {
18111809
impl<'a, 'gcx, 'tcx> VariantDefData<'tcx, 'static> {
18121810
#[inline]
18131811
pub fn is_uninhabited_recurse(&'tcx self,
1814-
visited: &mut HashMap<(DefId, &'tcx Substs<'tcx>), ()>,
1812+
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
18151813
block: Option<NodeId>,
18161814
cx: TyCtxt<'a, 'gcx, 'tcx>,
18171815
substs: &'tcx Substs<'tcx>,
@@ -1852,7 +1850,7 @@ impl<'a, 'gcx, 'tcx, 'container> FieldDefData<'tcx, 'container> {
18521850
impl<'a, 'gcx, 'tcx> FieldDefData<'tcx, 'static> {
18531851
#[inline]
18541852
pub fn is_uninhabited_recurse(&'tcx self,
1855-
visited: &mut HashMap<(DefId, &'tcx Substs<'tcx>), ()>,
1853+
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
18561854
block: Option<NodeId>,
18571855
tcx: TyCtxt<'a, 'gcx, 'tcx>,
18581856
substs: &'tcx Substs<'tcx>) -> bool {

src/librustc/ty/sty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use util::common::ErrorReported;
2121
use collections::enum_set::{self, EnumSet, CLike};
2222
use std::fmt;
2323
use std::ops;
24-
use std::collections::HashMap;
2524
use syntax::abi;
2625
use syntax::ast::{self, Name, NodeId};
2726
use syntax::symbol::{keywords, InternedString};
27+
use util::nodemap::FxHashSet;
2828

2929
use serialize;
3030

@@ -933,12 +933,12 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
933933
/// Checks whether a type is uninhabited.
934934
/// If `block` is `Some(id)` it also checks that the uninhabited-ness is visible from `id`.
935935
pub fn is_uninhabited(&self, block: Option<NodeId>, cx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
936-
let mut visited = HashMap::new();
936+
let mut visited = FxHashSet::default();
937937
self.is_uninhabited_recurse(&mut visited, block, cx)
938938
}
939939

940940
pub fn is_uninhabited_recurse(&self,
941-
visited: &mut HashMap<(DefId, &'tcx Substs<'tcx>), ()>,
941+
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
942942
block: Option<NodeId>,
943943
cx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
944944
match self.sty {

0 commit comments

Comments
 (0)