diff options
author | Thomas Haller <thaller@redhat.com> | 2018-04-10 14:38:14 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-04-13 09:09:46 +0200 |
commit | 04a42e2748478a6f6c204f94c7c83fa2c9b8dbd9 (patch) | |
tree | c773636a70ab4c3406683d3e1f59ebe69612c434 | |
parent | 457b08bbb6a0b19ecc05af57f8cb29ee974c8fe9 (diff) | |
download | NetworkManager-04a42e2748478a6f6c204f94c7c83fa2c9b8dbd9.tar.gz |
auth-chain: create data-hash hashtable only when needed
It makes sense to use NMAuthChain also when not attaching any user-data to
the chain. The main reason would be, the ability to schedule multiple permission
checks in parallel, and wait for them to complete together.
Only allocate the hash-table, when we really need it.
-rw-r--r-- | src/nm-auth-utils.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/nm-auth-utils.c b/src/nm-auth-utils.c index 66daeede3a..cba118250f 100644 --- a/src/nm-auth-utils.c +++ b/src/nm-auth-utils.c @@ -119,6 +119,8 @@ _get_data (NMAuthChain *self, const char *tag) { ChainData *tmp; + if (!self->data_hash) + return NULL; tmp = g_hash_table_lookup (self->data_hash, &tag); return tmp ? tmp->data : NULL; } @@ -152,6 +154,9 @@ nm_auth_chain_steal_data (NMAuthChain *self, const char *tag) g_return_val_if_fail (self, NULL); g_return_val_if_fail (tag, NULL); + if (!self->data_hash) + return NULL; + tmp = g_hash_table_lookup (self->data_hash, &tag); if (!tmp) return NULL; @@ -173,9 +178,14 @@ nm_auth_chain_set_data (NMAuthChain *self, g_return_if_fail (self); g_return_if_fail (tag); - if (data == NULL) - g_hash_table_remove (self->data_hash, &tag); - else { + if (data == NULL) { + if (self->data_hash) + g_hash_table_remove (self->data_hash, &tag); + } else { + if (!self->data_hash) { + self->data_hash = g_hash_table_new_full (nm_pstr_hash, nm_pstr_equal, + NULL, chain_data_free); + } g_hash_table_add (self->data_hash, chain_data_new (tag, data, data_destroy)); } @@ -331,7 +341,6 @@ nm_auth_chain_new_subject (NMAuthSubject *subject, self = g_slice_new0 (NMAuthChain); c_list_init (&self->auth_call_lst_head); self->refcount = 1; - self->data_hash = g_hash_table_new_full (nm_pstr_hash, nm_pstr_equal, NULL, chain_data_free); self->done_func = done_func; self->user_data = user_data; self->context = context ? g_object_ref (context) : NULL; |