diff options
author | Thomas Haller <thaller@redhat.com> | 2018-04-11 11:35:14 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-04-11 11:35:14 +0200 |
commit | 8c805c943cbc291da2adf49d7c517b010ab5801d (patch) | |
tree | c6c89886c2094b48b780efc6cad9b264691dad8b | |
parent | 8bb058386d6a74dcb5283f46c2b0aeb3d06a9c5c (diff) |
connectivity: optmize finding best connectivty state in NMManager::device_connectivity_changed()
It doesn't get better than FULL, so we can abort the loop in that
case early.
-rw-r--r-- | src/nm-manager.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/nm-manager.c b/src/nm-manager.c index cdaeb8a107..c267e465cf 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -2519,11 +2519,20 @@ device_connectivity_changed (NMDevice *device, NMConnectivityState state; NMDevice *dev; - c_list_for_each_entry (dev, &priv->devices_lst_head, devices_lst) { - state = nm_device_get_connectivity_state (dev); - if (state > best_state) + best_state = nm_device_get_connectivity_state (device); + if (best_state < NM_CONNECTIVITY_FULL) { + c_list_for_each_entry (dev, &priv->devices_lst_head, devices_lst) { + state = nm_device_get_connectivity_state (dev); + if (state <= best_state) + continue; best_state = state; + if (best_state >= NM_CONNECTIVITY_FULL) { + /* it doesn't get better than this. */ + break; + } + } } + nm_assert (best_state <= NM_CONNECTIVITY_FULL); if (best_state != priv->connectivity_state) { priv->connectivity_state = best_state; |