diff options
| author | Ajax <commial@gmail.com> | 2015-04-28 15:24:08 +0200 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2015-04-28 15:28:21 +0200 |
| commit | 6a693f9b2f8534486ad989b6f870b27a68445821 (patch) | |
| tree | a98190e5981fb3a233b12124c83611ccd9bd58bb /miasm2/core/graph.py | |
| parent | d6fef49f84a4c8ce286959097f5e028167c58549 (diff) | |
| download | miasm-6a693f9b2f8534486ad989b6f870b27a68445821.tar.gz miasm-6a693f9b2f8534486ad989b6f870b27a68445821.zip | |
DepGraph: Speed up 'add_uniq_edge' in the mean case
Diffstat (limited to 'miasm2/core/graph.py')
| -rw-r--r-- | miasm2/core/graph.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/miasm2/core/graph.py b/miasm2/core/graph.py index f7a9e8f4..3d1cb7c8 100644 --- a/miasm2/core/graph.py +++ b/miasm2/core/graph.py @@ -52,11 +52,11 @@ class DiGraph(object): self._nodes_succ[a].append(b) self._nodes_pred[b].append(a) - def add_uniq_edge(self, a, b): - if (a, b) in self._edges: - return - else: - self.add_edge(a, b) + def add_uniq_edge(self, src, dst): + """Add an edge from @src to @dst if it doesn't already exist""" + if (src not in self._nodes_succ or + dst not in self._nodes_succ[src]): + self.add_edge(src, dst) def del_edge(self, a, b): self._edges.remove((a, b)) |