diff --git a/src/util/hash_table.c b/src/util/hash_table.c index 7b2b7eb0d6a..596bab4c322 100644 --- a/src/util/hash_table.c +++ b/src/util/hash_table.c @@ -660,6 +660,21 @@ _mesa_pointer_hash_table_create(void *mem_ctx) _mesa_key_pointer_equal); } + +bool +_mesa_hash_table_reserve(struct hash_table *ht, unsigned size) +{ + if (size < ht->max_entries) + return true; + for (unsigned i = ht->size_index + 1; i < ARRAY_SIZE(hash_sizes); i++) { + if (hash_sizes[i].max_entries >= size) { + _mesa_hash_table_rehash(ht, i); + break; + } + } + return ht->max_entries >= size; +} + /** * Hash table wrapper which supports 64-bit keys. * diff --git a/src/util/hash_table.h b/src/util/hash_table.h index eabc88a5906..d59e33ff9f6 100644 --- a/src/util/hash_table.h +++ b/src/util/hash_table.h @@ -124,6 +124,8 @@ bool _mesa_key_pointer_equal(const void *a, const void *b); struct hash_table * _mesa_pointer_hash_table_create(void *mem_ctx); +bool +_mesa_hash_table_reserve(struct hash_table *ht, unsigned size); /** * This foreach function is safe against deletion (which just replaces * an entry's data with the deleted marker), but not against insertion