diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2017-04-20 04:45:53 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2017-04-30 17:02:59 -0400 |
| commit | c7dc39dbf095f04839b57a1e34afc6ab29d905d3 (patch) | |
| tree | af402b44cd3acabe29fce966c7ff781d203eede8 /src/librustc_data_structures | |
| parent | 55d6066c05fea0e0787ac5add67e26283468116c (diff) | |
| download | rust-c7dc39dbf095f04839b57a1e34afc6ab29d905d3.tar.gz rust-c7dc39dbf095f04839b57a1e34afc6ab29d905d3.zip | |
intern CodeExtents
Make a `CodeExtent<'tcx>` be something allocated in an arena instead of an index into the `RegionMaps`.
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/transitive_relation.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs index 2631108aeb5..b0fca5c0ff3 100644 --- a/src/librustc_data_structures/transitive_relation.rs +++ b/src/librustc_data_structures/transitive_relation.rs @@ -80,6 +80,27 @@ impl<T: Debug + PartialEq> TransitiveRelation<T> { } } + /// Applies the (partial) function to each edge and returns a new + /// relation. If `f` returns `None` for any end-point, returns + /// `None`. + pub fn maybe_map<F, U>(&self, mut f: F) -> Option<TransitiveRelation<U>> + where F: FnMut(&T) -> Option<U>, + U: Debug + PartialEq, + { + let mut result = TransitiveRelation::new(); + for edge in &self.edges { + let r = f(&self.elements[edge.source.0]).and_then(|source| { + f(&self.elements[edge.target.0]).and_then(|target| { + Some(result.add(source, target)) + }) + }); + if r.is_none() { + return None; + } + } + Some(result) + } + /// Indicate that `a < b` (where `<` is this relation) pub fn add(&mut self, a: T, b: T) { let a = self.add_index(a); |
