Mesa: short-circuit case when looking up the same program twice in cache

This commit is contained in:
Keith Whitwell 2008-10-03 16:46:48 +01:00
parent fa1b533012
commit d63a36ef3a
2 changed files with 22 additions and 9 deletions

View file

@ -44,6 +44,7 @@ struct cache_item
struct gl_program_cache
{
struct cache_item **items;
struct cache_item *last;
GLuint size, n_items;
};
@ -83,6 +84,8 @@ rehash(struct gl_program_cache *cache)
struct cache_item *c, *next;
GLuint size, i;
cache->last = NULL;
size = cache->size * 3;
items = (struct cache_item**) _mesa_malloc(size * sizeof(*items));
_mesa_memset(items, 0, size * sizeof(*items));
@ -105,6 +108,8 @@ clear_cache(GLcontext *ctx, struct gl_program_cache *cache)
{
struct cache_item *c, *next;
GLuint i;
cache->last = NULL;
for (i = 0; i < cache->size; i++) {
for (c = cache->items[i]; c; c = next) {
@ -149,18 +154,26 @@ _mesa_delete_program_cache(GLcontext *ctx, struct gl_program_cache *cache)
struct gl_program *
_mesa_search_program_cache(const struct gl_program_cache *cache,
_mesa_search_program_cache(struct gl_program_cache *cache,
const void *key, GLuint keysize)
{
const GLuint hash = hash_key(key, keysize);
struct cache_item *c;
for (c = cache->items[hash % cache->size]; c; c = c->next) {
if (c->hash == hash && memcmp(c->key, key, keysize) == 0)
return c->program;
if (cache->last &&
memcmp(cache->last->key, key, keysize) == 0) {
return cache->last->program;
}
else {
const GLuint hash = hash_key(key, keysize);
struct cache_item *c;
return NULL;
for (c = cache->items[hash % cache->size]; c; c = c->next) {
if (c->hash == hash && memcmp(c->key, key, keysize) == 0) {
cache->last = c;
return c->program;
}
}
return NULL;
}
}

View file

@ -42,7 +42,7 @@ _mesa_delete_program_cache(GLcontext *ctx, struct gl_program_cache *pc);
extern struct gl_program *
_mesa_search_program_cache(const struct gl_program_cache *cache,
_mesa_search_program_cache(struct gl_program_cache *cache,
const void *key, GLuint keysize);
extern void