diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-03-01 15:21:57 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-03-01 16:46:40 +0000 |
commit | effb76e25815c1263c14c3c4358ee6ccce39f60b (patch) | |
tree | ceaf4a3af3f26a62277f1b901d6c7759b7e7f83d | |
parent | 57700d3349b53d5adface4eaa57accaa896cde82 (diff) |
Add a configure option to disable hash-table entry caches
-rw-r--r-- | configure.ac | 9 | ||||
-rw-r--r-- | dbus/dbus-hash.c | 25 |
2 files changed, 31 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index 3da0bde1..ba6610d5 100644 --- a/configure.ac +++ b/configure.ac @@ -1649,6 +1649,15 @@ if test "x$enable_link_caches" = xyes; then [Define to reduce memory use at a performance cost]) fi +AC_ARG_ENABLE([hash-entry-caches], + [AS_HELP_STRING([--disable-hash-entry-caches], + [disable hash-table entry caches, decreasing performance and memory use])], + [], [enable_hash_entry_caches=yes]) +if test "x$enable_hash_entry_caches" = xyes; then + AC_DEFINE([DBUS_ENABLE_HASH_ENTRY_CACHES], [1], + [Define to improve performance at a small memory cost]) +fi + AC_CONFIG_FILES([ Doxyfile dbus/versioninfo.rc diff --git a/dbus/dbus-hash.c b/dbus/dbus-hash.c index 67ef4ced..4776b6d6 100644 --- a/dbus/dbus-hash.c +++ b/dbus/dbus-hash.c @@ -203,7 +203,9 @@ struct DBusHashTable { DBusFreeFunction free_key_function; /**< Function to free keys */ DBusFreeFunction free_value_function; /**< Function to free values */ +#ifdef DBUS_ENABLE_HASH_ENTRY_CACHES DBusMemPool *entry_pool; /**< Memory pool for hash entries */ +#endif }; /** @@ -295,21 +297,25 @@ _dbus_hash_table_new (DBusHashType type, DBusFreeFunction value_free_function) { DBusHashTable *table; +#ifdef DBUS_ENABLE_HASH_ENTRY_CACHES DBusMemPool *entry_pool; +#endif table = dbus_new0 (DBusHashTable, 1); if (table == NULL) return NULL; +#ifdef DBUS_ENABLE_HASH_ENTRY_CACHES entry_pool = _dbus_mem_pool_new (sizeof (DBusHashEntry), TRUE); if (entry_pool == NULL) { dbus_free (table); return NULL; } + table->entry_pool = entry_pool; +#endif table->refcount = 1; - table->entry_pool = entry_pool; _dbus_assert (DBUS_SMALL_HASH_TABLE == _DBUS_N_ELEMENTS (table->static_buckets)); @@ -378,7 +384,7 @@ _dbus_hash_table_unref (DBusHashTable *table) if (table->refcount == 0) { -#if 0 +#ifndef DBUS_ENABLE_HASH_ENTRY_CACHES DBusHashEntry *entry; DBusHashEntry *next; int i; @@ -444,8 +450,12 @@ alloc_entry (DBusHashTable *table) { DBusHashEntry *entry; +#ifdef DBUS_ENABLE_HASH_ENTRY_CACHES entry = _dbus_mem_pool_alloc (table->entry_pool); - +#else + entry = dbus_malloc0 (sizeof (DBusHashEntry)); +#endif + return entry; } @@ -464,7 +474,12 @@ free_entry (DBusHashTable *table, DBusHashEntry *entry) { free_entry_data (table, entry); + +#ifdef DBUS_ENABLE_HASH_ENTRY_CACHES _dbus_mem_pool_dealloc (table->entry_pool, entry); +#else + dbus_free (entry); +#endif } static void @@ -1651,7 +1666,11 @@ _dbus_hash_table_free_preallocated_entry (DBusHashTable *table, entry = (DBusHashEntry*) preallocated; /* Don't use free_entry(), since this entry has no key/data */ +#ifdef DBUS_ENABLE_HASH_ENTRY_CACHES _dbus_mem_pool_dealloc (table->entry_pool, entry); +#else + dbus_free (entry); +#endif } /** |