summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2015-06-07 00:58:36 +0200
committerJustus Winter <4winter@informatik.uni-hamburg.de>2015-11-12 22:21:17 +0100
commit226a9d9c34a2d187f978a25874488e5b07986d7c (patch)
tree70a0a89547be9857b188a48d56b5f943c5b6b8c7
parentc1d5c163a89f53a3c6e4e67f5f4119af96f7a470 (diff)
libihash: prefer performance degradation over failure
* libihash/ihash.c (hurd_ihash_add): Add the item even though we are above the load factor if resizing failed.
-rw-r--r--libihash/ihash.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/libihash/ihash.c b/libihash/ihash.c
index a97de3ee..87d7abf4 100644
--- a/libihash/ihash.c
+++ b/libihash/ihash.c
@@ -301,12 +301,14 @@ hurd_ihash_add (hurd_ihash_t ht, hurd_ihash_key_t key, hurd_ihash_value_t item)
{
struct hurd_ihash old_ht = *ht;
int was_added;
+ int fatal = 0; /* bail out on allocation errors */
unsigned int i;
if (ht->size)
{
/* Only fill the hash table up to its maximum load factor. */
if (hurd_ihash_get_load (ht) <= ht->max_load)
+ add_one:
if (add_one (ht, key, item))
return 0;
}
@@ -324,7 +326,15 @@ hurd_ihash_add (hurd_ihash_t ht, hurd_ihash_key_t key, hurd_ihash_value_t item)
if (ht->items == NULL)
{
*ht = old_ht;
- return ENOMEM;
+ if (fatal || ht->size == 0)
+ return ENOMEM;
+
+ /* We prefer performance degradation over failure. Therefore,
+ we add the item even though we are above the load factor. If
+ the table is full, this will fail. We set the fatal flag to
+ avoid looping. */
+ fatal = 1;
+ goto add_one;
}
/* We have to rehash the old entries. */