From a2c699856a2c0d5c1bf0a4cef5ef767127a2274f Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 20 Oct 2020 18:17:16 +0200 Subject: [PATCH] util: hash: Remove virHashCreateFull The only place we call it is in virHashNew. Move the code to virHashNew and remove virHashCreateFull. Code wishing to use non-strings as hash table keys will be better off using glib's GHashTable directly. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/util/virhash.c | 67 ++++++++++++---------------------------------- src/util/virhash.h | 7 ----- 2 files changed, 17 insertions(+), 57 deletions(-) diff --git a/src/util/virhash.c b/src/util/virhash.c index c781e1d5a5..8d56b4bb85 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -118,49 +118,6 @@ virHashComputeKey(const virHashTable *table, const void *name) return value % table->size; } -/** - * virHashCreateFull: - * @size: the size of the hash table - * @dataFree: callback to free data - * @keyCode: callback to compute hash code - * @keyEqual: callback to compare hash keys - * @keyCopy: callback to copy hash keys - * @keyFree: callback to free keys - * - * Create a new virHashTablePtr. - * - * Returns the newly created object. - */ -virHashTablePtr virHashCreateFull(ssize_t size, - virHashDataFree dataFree, - virHashKeyCode keyCode, - virHashKeyEqual keyEqual, - virHashKeyCopy keyCopy, - virHashKeyPrintHuman keyPrint, - virHashKeyFree keyFree) -{ - virHashTablePtr table = NULL; - - if (size <= 0) - size = 256; - - table = g_new0(virHashTable, 1); - - table->seed = virRandomBits(32); - table->size = size; - table->nbElems = 0; - table->dataFree = dataFree; - table->keyCode = keyCode; - table->keyEqual = keyEqual; - table->keyCopy = keyCopy; - table->keyPrint = keyPrint; - table->keyFree = keyFree; - - table->table = g_new0(virHashEntryPtr, table->size); - - return table; -} - /** * virHashNew: @@ -173,13 +130,23 @@ virHashTablePtr virHashCreateFull(ssize_t size, virHashTablePtr virHashNew(virHashDataFree dataFree) { - return virHashCreateFull(32, - dataFree, - virHashStrCode, - virHashStrEqual, - virHashStrCopy, - virHashStrPrintHuman, - virHashStrFree); + virHashTablePtr table = NULL; + + table = g_new0(virHashTable, 1); + + table->seed = virRandomBits(32); + table->size = 32; + table->nbElems = 0; + table->dataFree = dataFree; + table->keyCode = virHashStrCode; + table->keyEqual = virHashStrEqual; + table->keyCopy = virHashStrCopy; + table->keyPrint = virHashStrPrintHuman; + table->keyFree = virHashStrFree; + + table->table = g_new0(virHashEntryPtr, table->size); + + return table; } diff --git a/src/util/virhash.h b/src/util/virhash.h index 2d221dce25..a9b022f362 100644 --- a/src/util/virhash.h +++ b/src/util/virhash.h @@ -113,13 +113,6 @@ typedef void (*virHashKeyFree)(void *name); */ virHashTablePtr virHashNew(virHashDataFree dataFree); virHashAtomicPtr virHashAtomicNew(virHashDataFree dataFree); -virHashTablePtr virHashCreateFull(ssize_t size, - virHashDataFree dataFree, - virHashKeyCode keyCode, - virHashKeyEqual keyEqual, - virHashKeyCopy keyCopy, - virHashKeyPrintHuman keyPrint, - virHashKeyFree keyFree); void virHashFree(virHashTablePtr table); ssize_t virHashSize(const virHashTable *table);