libnm-util: minor refactoring in nm_connection_compare()

Evaluate a cheaper comparison first, to fail early

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2013-12-12 11:22:53 +01:00 committed by Dan Williams
parent d988a52967
commit b7f6169dbd

View file

@ -446,11 +446,16 @@ nm_connection_compare (NMConnection *a,
GHashTableIter iter;
NMSetting *src;
if (!a && !b)
if (a == b)
return TRUE;
if (!a || !b)
return FALSE;
/* B / A: ensure settings in B that are not in A make the comparison fail */
if (g_hash_table_size (NM_CONNECTION_GET_PRIVATE (a)->settings) !=
g_hash_table_size (NM_CONNECTION_GET_PRIVATE (b)->settings))
return FALSE;
/* A / B: ensure all settings in A match corresponding ones in B */
g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (a)->settings);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &src)) {
@ -460,11 +465,6 @@ nm_connection_compare (NMConnection *a,
return FALSE;
}
/* B / A: ensure settings in B that are not in A make the comparison fail */
if (g_hash_table_size (NM_CONNECTION_GET_PRIVATE (a)->settings) !=
g_hash_table_size (NM_CONNECTION_GET_PRIVATE (b)->settings))
return FALSE;
return TRUE;
}