mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 15:38:09 +02:00
mesa: use binary search for MESA_EXTENSION_OVERRIDE
Not a hot path obviously, but the table still has 425 extensions, which you can go through in just 9 steps with a binary search. The table is already sorted, as required by other parts of the code and enforced by mesa's `main-test`. Signed-off-by: Eric Engestrom <eric.engestrom@intel.com> Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
This commit is contained in:
parent
b738d4494c
commit
74f064ae90
1 changed files with 16 additions and 6 deletions
|
|
@ -48,6 +48,13 @@ static char *unrecognized_extensions = NULL;
|
|||
*/
|
||||
#define o(x) offsetof(struct gl_extensions, x)
|
||||
|
||||
static int
|
||||
extension_name_compare(const void *name, const void *elem)
|
||||
{
|
||||
const struct mesa_extension *entry = elem;
|
||||
return strcmp(name, entry->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an extension name, lookup up the corresponding member of struct
|
||||
* gl_extensions and return that member's index. If the name is
|
||||
|
|
@ -59,15 +66,18 @@ static char *unrecognized_extensions = NULL;
|
|||
static int
|
||||
name_to_index(const char* name)
|
||||
{
|
||||
unsigned i;
|
||||
const struct mesa_extension *entry;
|
||||
|
||||
if (name == 0)
|
||||
if (!name)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < MESA_EXTENSION_COUNT; ++i) {
|
||||
if (strcmp(name, _mesa_extension_table[i].name) == 0)
|
||||
return i;
|
||||
}
|
||||
entry = bsearch(name,
|
||||
_mesa_extension_table, MESA_EXTENSION_COUNT,
|
||||
sizeof(_mesa_extension_table[0]),
|
||||
extension_name_compare);
|
||||
|
||||
if (entry)
|
||||
return entry - _mesa_extension_table;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue