]> git.lizzy.rs Git - rust.git/commitdiff
in which `NodeMap` and friends are macrotized!
authorZack M. Davis <code@zackmdavis.net>
Mon, 21 May 2018 06:15:07 +0000 (23:15 -0700)
committerZack M. Davis <code@zackmdavis.net>
Mon, 28 May 2018 16:20:14 +0000 (09:20 -0700)
src/librustc/util/nodemap.rs

index c92aa24b8cf5a93681a70a605826124840a39eae..0dc71af9db694f1e015dfdd8dc185f09774305bf 100644 (file)
 pub use rustc_data_structures::fx::FxHashMap;
 pub use rustc_data_structures::fx::FxHashSet;
 
-pub type NodeMap<T> = FxHashMap<ast::NodeId, T>;
-pub type DefIdMap<T> = FxHashMap<DefId, T>;
-pub type HirIdMap<T> = FxHashMap<HirId, T>;
-pub type ItemLocalMap<T> = FxHashMap<ItemLocalId, T>;
+macro_rules! define_id_collections {
+    ($map_name:ident, $set_name:ident, $key:ty) => {
+        pub type $map_name<T> = FxHashMap<$key, T>;
+        pub fn $map_name<T>() -> $map_name<T> { FxHashMap() }
+        pub type $set_name = FxHashSet<$key>;
+        pub fn $set_name() -> $set_name { FxHashSet() }
+    }
+}
 
-pub type NodeSet = FxHashSet<ast::NodeId>;
-pub type DefIdSet = FxHashSet<DefId>;
-pub type HirIdSet = FxHashSet<HirId>;
-pub type ItemLocalSet = FxHashSet<ItemLocalId>;
-
-pub fn NodeMap<T>() -> NodeMap<T> { FxHashMap() }
-pub fn DefIdMap<T>() -> DefIdMap<T> { FxHashMap() }
-pub fn HirIdMap<T>() -> HirIdMap<T> { FxHashMap() }
-pub fn ItemLocalMap<T>() -> ItemLocalMap<T> { FxHashMap() }
-pub fn NodeSet() -> NodeSet { FxHashSet() }
-pub fn DefIdSet() -> DefIdSet { FxHashSet() }
-pub fn HirIdSet() -> HirIdSet { FxHashSet() }
-pub fn ItemLocalSet() -> ItemLocalSet { FxHashSet() }
+define_id_collections!(NodeMap, NodeSet, ast::NodeId);
+define_id_collections!(DefIdMap, DefIdSet, DefId);
+define_id_collections!(HirIdMap, HirIdSet, HirId);
+define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId);