From 245f0e0b35d385e966289080dbd2594e74a189b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= Date: Thu, 3 Apr 2025 09:32:26 +0200 Subject: [PATCH] core: optimize hash table search in _ethtool_fec_set Break the loop as soon as we've found the value. Fixes: 19bed3121fb6 ('ethtool: support Forward Error Correction(fec)') --- src/core/devices/nm-device.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index c2509ff95..d86684944 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -2788,13 +2788,11 @@ _ethtool_fec_set(NMDevice *self, g_hash_table_iter_init(&iter, hash); while (g_hash_table_iter_next(&iter, (gpointer *) &name, (gpointer *) &variant)) { - NMEthtoolID ethtool_id = nm_ethtool_id_get_by_name(name); - - if (!nm_ethtool_id_is_fec(ethtool_id)) - continue; - - nm_assert(g_variant_is_of_type(variant, G_VARIANT_TYPE_UINT32)); - fec_mode = g_variant_get_uint32(variant); + if (nm_ethtool_id_is_fec(nm_ethtool_id_get_by_name(name))) { + nm_assert(g_variant_is_of_type(variant, G_VARIANT_TYPE_UINT32)); + fec_mode = g_variant_get_uint32(variant); + break; + } } /* The NM_SETTING_ETHTOOL_FEC_MODE_NONE is query only value, hence do nothing. */