summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/translate
diff options
context:
space:
mode:
authorKeith Whitwell <keith@tungstengraphics.com>2008-05-09 13:09:58 +0100
committerKeith Whitwell <keith@tungstengraphics.com>2008-05-12 17:40:54 +0100
commitc0a6040f568e0c9be07797b2dc2fdd8a3624ec34 (patch)
treee4a20c2141de80e8d7e04150e4c5ef989ba427fd /src/gallium/auxiliary/translate
parent501be9c7dd0cc5f985c708fa0e5f35d7fd20deb4 (diff)
translate: helper functions for mimizing cost of key compares
Diffstat (limited to 'src/gallium/auxiliary/translate')
-rw-r--r--src/gallium/auxiliary/translate/translate.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/translate/translate.h b/src/gallium/auxiliary/translate/translate.h
index de6f09d18a..b8210af50c 100644
--- a/src/gallium/auxiliary/translate/translate.h
+++ b/src/gallium/auxiliary/translate/translate.h
@@ -95,6 +95,27 @@ struct translate *translate_lookup_or_create( struct translate_context *tctx,
struct translate *translate_create( const struct translate_key *key );
+static INLINE int translate_keysize( const struct translate_key *key )
+{
+ return 2 * sizeof(int) + key->nr_elements * sizeof(struct translate_element);
+}
+
+static INLINE int translate_key_compare( const struct translate_key *a,
+ const struct translate_key *b )
+{
+ int keysize = translate_keysize(a);
+ return memcmp(a, b, keysize);
+}
+
+
+static INLINE void translate_key_sanitize( struct translate_key *a )
+{
+ int keysize = translate_keysize(a);
+ char *ptr = (char *)a;
+ memset(ptr + keysize, 0, sizeof(*a) - keysize);
+}
+
+
/*******************************************************************************
* Private:
*/