gallium: fix broken hashing for vertex translation
authorBrian Paul <brian.paul@tungstengraphics.com>
Wed, 23 Apr 2008 16:29:52 +0000 (10:29 -0600)
committerBrian Paul <brian.paul@tungstengraphics.com>
Wed, 23 Apr 2008 16:29:52 +0000 (10:29 -0600)
It seems we get hash collisions fairly easily and the code as it was didn't
deal with that properly.

I think we need a simpler hashing interface...

src/gallium/auxiliary/draw/draw_pt_fetch.c

index 93da811ed81317cc910e001600423ed453b8ba7d..a8d4be5b64b95bb1eb24e1e60527f805ada8b8d8 100644 (file)
@@ -70,13 +70,21 @@ static struct translate *cached_translate(struct pt_fetch *fetch,
    struct cso_hash_iter iter = cso_hash_find(fetch->hash, hash_key);
    struct translate *translate = 0;
 
-   if (cso_hash_iter_is_null(iter)) {
+   while (!cso_hash_iter_is_null(iter)) {
+      void *iter_data = cso_hash_iter_data(iter);
+      if (memcmp(iter_data, key, sizeof(*key)) == 0) {
+         /* found */
+         translate = cso_hash_iter_data(iter);
+         break;
+      }
+      iter = cso_hash_iter_next(iter);
+      /*debug_printf("\tOK with %d\n", hash_key);*/
+   }
+
+   if (!translate) {
+      /* create/insert */
       translate = translate_create(key);
       cso_hash_insert(fetch->hash, hash_key, translate);
-      /*debug_printf("\tCREATED with %d\n", hash_key);*/
-   } else {
-      translate = cso_hash_iter_data(iter);
-      /*debug_printf("\tOK with %d\n", hash_key);*/
    }
 
    return translate;