From 60ffadcbc0715ef736a81f5a4c2b5924cd8b04f6 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Mon, 17 Aug 2020 15:10:31 +0200 Subject: [PATCH] mesa: add _mesa_HashFindFreeKeys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _mesa_HashFindFreeKeyBlock function returns a name range, so it cannot be used to recycle non-consecutive names. Reviewed-by: Marek Olšák Part-of: --- src/mesa/main/hash.c | 19 +++++++++++++++++++ src/mesa/main/hash.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/mesa/main/hash.c b/src/mesa/main/hash.c index e0d71dad3bf..2f36fc84425 100644 --- a/src/mesa/main/hash.c +++ b/src/mesa/main/hash.c @@ -446,6 +446,25 @@ _mesa_HashFindFreeKeyBlock(struct _mesa_HashTable *table, GLuint numKeys) } +bool +_mesa_HashFindFreeKeys(struct _mesa_HashTable *table, GLuint* keys, GLuint numKeys) +{ + if (!table->id_alloc) { + GLuint first = _mesa_HashFindFreeKeyBlock(table, numKeys); + for (int i = 0; i < numKeys; i++) { + keys[i] = first + i; + } + return first != 0; + } + + for (int i = 0; i < numKeys; i++) { + keys[i] = util_idalloc_alloc(table->id_alloc); + } + + return true; +} + + /** * Return the number of entries in the hash table. */ diff --git a/src/mesa/main/hash.h b/src/mesa/main/hash.h index a0411651384..98647674467 100644 --- a/src/mesa/main/hash.h +++ b/src/mesa/main/hash.h @@ -178,6 +178,9 @@ extern void _mesa_HashPrint(const struct _mesa_HashTable *table); extern GLuint _mesa_HashFindFreeKeyBlock(struct _mesa_HashTable *table, GLuint numKeys); +extern bool +_mesa_HashFindFreeKeys(struct _mesa_HashTable *table, GLuint* keys, GLuint numKeys); + extern GLuint _mesa_HashNumEntries(const struct _mesa_HashTable *table);