OSDN Git Service

mesa: glGet: simplify the 'enum not found' condition
authorImre Deak <imre.deak@intel.com>
Mon, 10 Sep 2012 05:46:02 +0000 (08:46 +0300)
committerOliver McFadden <oliver.mcfadden@linux.intel.com>
Wed, 10 Oct 2012 09:43:08 +0000 (12:43 +0300)
When traversing the hash table looking up an enum that is invalid we
eventually reach the first element in the descriptor array. By looking
at the type of that element, which is always TYPE_API_MASK, we know that
we can stop the search and return error. Since this element is always
the first it's enough to check for its index being 0 without looking at
its type.

Later in this patchset, when we generate the hash tables during build
time, this will allow us to remove the TYPE_API_MASK and related flags
completly.

Signed-off-by: Imre Deak <imre.deak@intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Oliver McFadden <oliver.mcfadden@linux.intel.com>
src/mesa/main/get.c

index b46492c..e09147b 100644 (file)
@@ -2004,16 +2004,18 @@ find_value(const char *func, GLenum pname, void **p, union value *v)
    mask = Elements(table[api]) - 1;
    hash = (pname * prime_factor);
    while (1) {
-      d = &values[table[api][hash & mask]];
+      int idx = table[api][hash & mask];
 
       /* If the enum isn't valid, the hash walk ends with index 0,
-       * which is the API mask entry at the beginning of values[]. */
-      if (unlikely(d->type == TYPE_API_MASK)) {
+       * pointing to the first entry of values[] which doesn't hold
+       * any valid enum. */
+      if (unlikely(idx == 0)) {
          _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
                _mesa_lookup_enum_by_nr(pname));
          return &error_value;
       }
 
+      d = &values[idx];
       if (likely(d->pname == pname))
          break;