|
|
0d097b |
From d0eb88089b059bfe2da3bd1a3797b89d69119c29 Mon Sep 17 00:00:00 2001
|
|
|
0d097b |
From: Alexey Tikhonov <atikhono@redhat.com>
|
|
|
0d097b |
Date: Thu, 23 Jan 2020 19:00:27 +0100
|
|
|
0d097b |
Subject: [PATCH 19/23] sss_ptr_hash: sss_ptr_hash_delete fix/optimization
|
|
|
0d097b |
MIME-Version: 1.0
|
|
|
0d097b |
Content-Type: text/plain; charset=UTF-8
|
|
|
0d097b |
Content-Transfer-Encoding: 8bit
|
|
|
0d097b |
|
|
|
0d097b |
- no reason to skip hash_delete() just because sss_ptr_hash_lookup_internal()
|
|
|
0d097b |
failed
|
|
|
0d097b |
- avoid excessive lookup if it is not required to free payload
|
|
|
0d097b |
|
|
|
0d097b |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
0d097b |
---
|
|
|
0d097b |
src/util/sss_ptr_hash.c | 17 +++++++++--------
|
|
|
0d097b |
1 file changed, 9 insertions(+), 8 deletions(-)
|
|
|
0d097b |
|
|
|
0d097b |
diff --git a/src/util/sss_ptr_hash.c b/src/util/sss_ptr_hash.c
|
|
|
0d097b |
index f8addec1e..7326244e6 100644
|
|
|
0d097b |
--- a/src/util/sss_ptr_hash.c
|
|
|
0d097b |
+++ b/src/util/sss_ptr_hash.c
|
|
|
0d097b |
@@ -331,20 +331,21 @@ void sss_ptr_hash_delete(hash_table_t *table,
|
|
|
0d097b |
struct sss_ptr_hash_value *value;
|
|
|
0d097b |
hash_key_t table_key;
|
|
|
0d097b |
int hret;
|
|
|
0d097b |
- void *ptr;
|
|
|
0d097b |
+ void *payload;
|
|
|
0d097b |
|
|
|
0d097b |
if (table == NULL || key == NULL) {
|
|
|
0d097b |
return;
|
|
|
0d097b |
}
|
|
|
0d097b |
|
|
|
0d097b |
- value = sss_ptr_hash_lookup_internal(table, key);
|
|
|
0d097b |
- if (value == NULL) {
|
|
|
0d097b |
- /* Value not found. */
|
|
|
0d097b |
- return;
|
|
|
0d097b |
+ if (free_value) {
|
|
|
0d097b |
+ value = sss_ptr_hash_lookup_internal(table, key);
|
|
|
0d097b |
+ if (value == NULL) {
|
|
|
0d097b |
+ free_value = false;
|
|
|
0d097b |
+ } else {
|
|
|
0d097b |
+ payload = value->ptr;
|
|
|
0d097b |
+ }
|
|
|
0d097b |
}
|
|
|
0d097b |
|
|
|
0d097b |
- ptr = value->ptr;
|
|
|
0d097b |
-
|
|
|
0d097b |
table_key.type = HASH_KEY_STRING;
|
|
|
0d097b |
table_key.str = discard_const_p(char, key);
|
|
|
0d097b |
|
|
|
0d097b |
@@ -357,7 +358,7 @@ void sss_ptr_hash_delete(hash_table_t *table,
|
|
|
0d097b |
|
|
|
0d097b |
/* Also free the original value if requested. */
|
|
|
0d097b |
if (free_value) {
|
|
|
0d097b |
- talloc_free(ptr);
|
|
|
0d097b |
+ talloc_free(payload);
|
|
|
0d097b |
}
|
|
|
0d097b |
|
|
|
0d097b |
return;
|
|
|
0d097b |
--
|
|
|
0d097b |
2.20.1
|
|
|
0d097b |
|