From b7f6169dbd53e7eeb3d1aea159275a369d718ac5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 12 Dec 2013 11:22:53 +0100 Subject: [PATCH] libnm-util: minor refactoring in nm_connection_compare() Evaluate a cheaper comparison first, to fail early Signed-off-by: Thomas Haller --- libnm-util/nm-connection.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c index 991fed62a8..7a4e219cec 100644 --- a/libnm-util/nm-connection.c +++ b/libnm-util/nm-connection.c @@ -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; }