summaryrefslogtreecommitdiff
path: root/networkx
diff options
context:
space:
mode:
authorAndrew Eckart <andrew.g.eckart@gmail.com>2021-08-28 12:58:10 -0500
committerGitHub <noreply@github.com>2021-08-28 10:58:10 -0700
commit7090340356943548ea5c7691ed2a676a63a1ed46 (patch)
treef2fcb17f2f5fafec364a61ca41dd45da3d0d3ca8 /networkx
parentf27522c9717ea5455d4634f9ed71d3f5e48e5528 (diff)
downloadnetworkx-7090340356943548ea5c7691ed2a676a63a1ed46.tar.gz
Store `G.adj` as a local variable to speed up `complement_edges(G)` (#5032)
Diffstat (limited to 'networkx')
-rw-r--r--networkx/algorithms/connectivity/edge_augmentation.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/networkx/algorithms/connectivity/edge_augmentation.py b/networkx/algorithms/connectivity/edge_augmentation.py
index dc8b8607..2939d3bc 100644
--- a/networkx/algorithms/connectivity/edge_augmentation.py
+++ b/networkx/algorithms/connectivity/edge_augmentation.py
@@ -1124,15 +1124,16 @@ def complement_edges(G):
>>> sorted(complement_edges(G))
[]
"""
+ G_adj = G._adj # Store as a variable to eliminate attribute lookup
if G.is_directed():
for u, v in it.combinations(G.nodes(), 2):
- if v not in G.adj[u]:
+ if v not in G_adj[u]:
yield (u, v)
- if u not in G.adj[v]:
+ if u not in G_adj[v]:
yield (v, u)
else:
for u, v in it.combinations(G.nodes(), 2):
- if v not in G.adj[u]:
+ if v not in G_adj[u]:
yield (u, v)