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

Joshua Colp asteriskteam at digium.com
Wed Aug 8 05:52:48 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/9825 )

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(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



diff --git a/include/asterisk/stasis.h b/include/asterisk/stasis.h
index 0373eeb..bca6d40 100644
--- a/include/asterisk/stasis.h
+++ b/include/asterisk/stasis.h
@@ -319,6 +319,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
+ */
+unsigned 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 ca17bdd..8c3c7f1 100644
--- a/main/stasis_cache.c
+++ b/main/stasis_cache.c
@@ -174,7 +174,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 88db49f..482dd01 100644
--- a/main/stasis_message.c
+++ b/main/stasis_message.c
@@ -32,11 +32,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;
+	unsigned int hash;
 };
 
 static struct stasis_message_vtable null_vtable = {};
@@ -73,6 +75,7 @@
 		ao2_cleanup(type);
 		return STASIS_MESSAGE_TYPE_ERROR;
 	}
+	type->hash = ast_hashtab_hash_string(name);
 	type->vtable = vtable;
 	*result = type;
 
@@ -84,6 +87,11 @@
 	return type->name;
 }
 
+unsigned 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/9825
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: merged
Gerrit-Change-Id: I4fe6bfdafb55bf5c322dd313fbd8c32cce73ef37
Gerrit-Change-Number: 9825
Gerrit-PatchSet: 2
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180808/4f6c5424/attachment-0001.html>


More information about the asterisk-code-review mailing list