Skip to content

Commit

Permalink
program: use immutable and mutable label iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
m4b committed Jul 7, 2017
1 parent 9eb8981 commit b7802d0
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions core/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,41 +98,24 @@ impl Program {

/// Returns the function with UUID `a`.
pub fn find_function_by_uuid<'a>(&'a self, a: &Uuid) -> Option<&'a Function> {
self.call_graph
.vertices()
.find(
|&x| match self.call_graph.vertex_label(x) {
Some(&CallTarget::Concrete(ref s)) => s.uuid() == a,
_ => false,
}
)
.and_then(
|r| match self.call_graph.vertex_label(r) {
Some(&CallTarget::Concrete(ref s)) => Some(s),
_ => None,
}
)
for ct in self.call_graph.vertex_labels() {
match ct {
&CallTarget::Concrete(ref s) => if s.uuid() == a { return Some(s) },
_ => (),
}
}
None
}

/// Returns the function with UUID `a`.
pub fn find_function_by_uuid_mut<'a>(&'a mut self, a: &Uuid) -> Option<&'a mut Function> {
let ct = self.call_graph
.vertices()
.find(
|&x| match self.call_graph.vertex_label(x) {
Some(&CallTarget::Concrete(ref s)) => s.uuid() == a,
_ => false,
}
);

if ct.is_none() {
return None;
}

match self.call_graph.vertex_label_mut(ct.unwrap()) {
Some(&mut CallTarget::Concrete(ref mut s)) => Some(s),
_ => None,
for ct in self.call_graph.vertex_labels_mut() {
match ct {
&mut CallTarget::Concrete(ref mut s) => if s.uuid() == a { return Some(s) },
_ => (),
}
}
None
}

/// Puts function/reference `new_ct` into the call graph, returning the UUIDs of all functions
Expand Down

0 comments on commit b7802d0

Please sign in to comment.