[Asterisk-code-review] stasis: Reduce calculation of stasis message type hash. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Mon Aug 6 06:37:47 CDT 2018


Joshua Colp has uploaded this change for review. ( https://gerrit.asterisk.org/9823


Change subject: stasis: Reduce calculation of stasis message type hash.
......................................................................

stasis: Reduce calculation of stasis message type hash.

When the stasis cache is used a hash is calculated for
retrieving or inserting messages. This change calculates
a hash when the message type is initialized that is then
used each time needed. This ensures that the hash is
calculated only once for the message type.

Change-Id: I4fe6bfdafb55bf5c322dd313fbd8c32cce73ef37
---
M include/asterisk/stasis.h
M main/stasis_cache.c
M main/stasis_message.c
3 files changed, 17 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/23/9823/1

diff --git a/include/asterisk/stasis.h b/include/asterisk/stasis.h
index 898fad4..bd0b7ce 100644
--- a/include/asterisk/stasis.h
+++ b/include/asterisk/stasis.h
@@ -321,6 +321,14 @@
 const char *stasis_message_type_name(const struct stasis_message_type *type);
 
 /*!
+ * \brief Gets the hash of a given message type
+ * \param type The type to get the hash of.
+ * \return The hash
+ * \since 13.24.0
+ */
+int stasis_message_type_hash(const struct stasis_message_type *type);
+
+/*!
  * \brief Check whether a message type is declined
  *
  * \param name The name of the message type to check
diff --git a/main/stasis_cache.c b/main/stasis_cache.c
index ee9e56d..a34e9be 100644
--- a/main/stasis_cache.c
+++ b/main/stasis_cache.c
@@ -176,7 +176,7 @@
 
 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 = stasis_message_type_hash(key->type);
 	key->hash += ast_hashtab_hash_string(key->id);
 }
 
diff --git a/main/stasis_message.c b/main/stasis_message.c
index 99721ef..697276a 100644
--- a/main/stasis_message.c
+++ b/main/stasis_message.c
@@ -34,11 +34,13 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/stasis.h"
 #include "asterisk/utils.h"
+#include "asterisk/hashtab.h"
 
 /*! \internal */
 struct stasis_message_type {
 	struct stasis_message_vtable *vtable;
 	char *name;
+	int hash;
 };
 
 static struct stasis_message_vtable null_vtable = {};
@@ -75,6 +77,7 @@
 		ao2_cleanup(type);
 		return STASIS_MESSAGE_TYPE_ERROR;
 	}
+	type->hash = ast_hashtab_hash_string(name);
 	type->vtable = vtable;
 	*result = type;
 
@@ -86,6 +89,11 @@
 	return type->name;
 }
 
+int stasis_message_type_hash(const struct stasis_message_type *type)
+{
+	return type->hash;
+}
+
 /*! \internal */
 struct stasis_message {
 	/*! Time the message was created */

-- 
To view, visit https://gerrit.asterisk.org/9823
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4fe6bfdafb55bf5c322dd313fbd8c32cce73ef37
Gerrit-Change-Number: 9823
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180806/36115706/attachment-0001.html>


More information about the asterisk-code-review mailing list