[svn-commits] mjordan: branch mjordan/12-stasis-performance r414971 - /team/mjordan/12-stas...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat May 31 14:33:04 CDT 2014


Author: mjordan
Date: Sat May 31 14:33:01 2014
New Revision: 414971

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=414971
Log:
stasis_cache: Mini-optimization - store hash result in cache entries

This knocks the call to ast_hashtab_hash_string down a few pegs

Modified:
    team/mjordan/12-stasis-performance/main/stasis_cache.c

Modified: team/mjordan/12-stasis-performance/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-stasis-performance/main/stasis_cache.c?view=diff&rev=414971&r1=414970&r2=414971
==============================================================================
--- team/mjordan/12-stasis-performance/main/stasis_cache.c (original)
+++ team/mjordan/12-stasis-performance/main/stasis_cache.c Sat May 31 14:33:01 2014
@@ -129,7 +129,8 @@
 
 struct cache_entry_key {
 	struct stasis_message_type *type;
-	const char *id;
+	const char *id;	
+	unsigned int hash;
 };
 
 struct stasis_cache_entry {
@@ -166,6 +167,12 @@
 	AST_VECTOR_FREE(&entry->remote);
 }
 
+static void cache_entry_compute_hash(struct cache_entry_key *key)
+{
+	key->hash = ast_hashtab_hash_string(stasis_message_type_name(key->type));
+	key->hash += ast_hashtab_hash_string(key->id);
+}
+
 static struct stasis_cache_entry *cache_entry_create(struct stasis_message_type *type, const char *id, struct stasis_message *snapshot)
 {
 	struct stasis_cache_entry *entry;
@@ -187,6 +194,7 @@
 		return NULL;
 	}
 	entry->key.type = ao2_bump(type);
+	cache_entry_compute_hash(&entry->key);
 
 	is_remote = ast_eid_cmp(&ast_eid_default, stasis_message_eid(snapshot)) ? 1 : 0;
 	if (AST_VECTOR_INIT(&entry->remote, is_remote)) {
@@ -211,7 +219,6 @@
 {
 	const struct stasis_cache_entry *object;
 	const struct cache_entry_key *key;
-	int hash = 0;
 
 	switch (flags & OBJ_SEARCH_MASK) {
 	case OBJ_SEARCH_KEY:
@@ -227,9 +234,7 @@
 		return 0;
 	}
 
-	hash += ast_hashtab_hash_string(stasis_message_type_name(key->type));
-	hash += ast_hashtab_hash_string(key->id);
-	return hash;
+	return (int)key->hash;
 }
 
 static int cache_entry_cmp(void *obj, void *arg, int flags)
@@ -347,6 +352,7 @@
 
 	search_key.type = type;
 	search_key.id = id;
+	cache_entry_compute_hash(&search_key);
 	entry = ao2_find(entries, &search_key, OBJ_SEARCH_KEY | OBJ_NOLOCK);
 
 	/* Ensure that what we looked for is what we found. */




More information about the svn-commits mailing list