summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-05-24 09:08:07 +0200
committerThomas Haller <thaller@redhat.com>2022-05-31 18:32:36 +0200
commit0f6df633faf3b1ecd394bda7547b94dfca104bda (patch)
tree579dc7b5513b048e314de6fba0227e765b644822
parent4f13383460af37dcbbe9b5631ac60a4c63e73a39 (diff)
downloadNetworkManager-0f6df633faf3b1ecd394bda7547b94dfca104bda.tar.gz
dhcp: minor cleanup of accept/decline functions in "nm-dhcp-client.c"
- assign the result of NM_DHCP_CLIENT_GET_CLASS() to a local variable. It feels nicer to only call the macro once. Of course, the macro expands to plain pointer dereferences, so there is little difference in terms of executed code. - handle the default case with no virtual function first.
-rw-r--r--src/core/dhcp/nm-dhcp-client.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c
index be1a7c8f5b..836d40f93f 100644
--- a/src/core/dhcp/nm-dhcp-client.c
+++ b/src/core/dhcp/nm-dhcp-client.c
@@ -486,32 +486,34 @@ nm_dhcp_client_stop_watch_child(NMDhcpClient *self, pid_t pid)
static gboolean
_dhcp_client_accept(NMDhcpClient *self, const NML3ConfigData *l3cd, GError **error)
{
- NMDhcpClientPrivate *priv;
+ NMDhcpClientClass *klass;
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
nm_assert(l3cd);
- priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
+ klass = NM_DHCP_CLIENT_GET_CLASS(self);
- g_return_val_if_fail(priv->l3cd, FALSE);
+ g_return_val_if_fail(NM_DHCP_CLIENT_GET_PRIVATE(self)->l3cd, FALSE);
- if (NM_DHCP_CLIENT_GET_CLASS(self)->accept) {
- return NM_DHCP_CLIENT_GET_CLASS(self)->accept(self, l3cd, error);
- }
+ if (!klass->accept)
+ return TRUE;
- return TRUE;
+ return klass->accept(self, l3cd, error);
}
static gboolean
_dhcp_client_can_accept(NMDhcpClient *self)
{
gboolean can_accept;
+ NMDhcpClientClass *klass;
- g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
+ nm_assert(NM_IS_DHCP_CLIENT(self));
- can_accept = !!(NM_DHCP_CLIENT_GET_CLASS(self)->accept);
+ klass = NM_DHCP_CLIENT_GET_CLASS(self);
- nm_assert(can_accept == (!!(NM_DHCP_CLIENT_GET_CLASS(self)->decline)));
+ can_accept = !!klass->accept;
+
+ nm_assert(can_accept == (!!klass->decline));
return can_accept;
}
@@ -522,20 +524,19 @@ _dhcp_client_decline(NMDhcpClient *self,
const char *error_message,
GError **error)
{
- NMDhcpClientPrivate *priv;
+ NMDhcpClientClass *klass;
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
nm_assert(l3cd);
- priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
+ klass = NM_DHCP_CLIENT_GET_CLASS(self);
- g_return_val_if_fail(priv->l3cd, FALSE);
+ g_return_val_if_fail(NM_DHCP_CLIENT_GET_PRIVATE(self)->l3cd, FALSE);
- if (NM_DHCP_CLIENT_GET_CLASS(self)->decline) {
- return NM_DHCP_CLIENT_GET_CLASS(self)->decline(self, l3cd, error_message, error);
- }
+ if (!klass->decline)
+ return TRUE;
- return TRUE;
+ return klass->decline(self, l3cd, error_message, error);
}
static GBytes *