From: Joshua Colp Date: Mon, 6 Aug 2018 11:36:22 +0000 (-0300) Subject: stasis: Reduce calculation of stasis message type hash. X-Git-Tag: 13.23.0-rc1~28^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=856b6d19543b58864e32be811e9ce7efe14da431;p=thirdparty%2Fasterisk.git 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 --- diff --git a/include/asterisk/stasis.h b/include/asterisk/stasis.h index 898fad4906..28c528232a 100644 --- a/include/asterisk/stasis.h +++ b/include/asterisk/stasis.h @@ -320,6 +320,14 @@ enum stasis_message_type_result stasis_message_type_create(const char *name, */ 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 * diff --git a/main/stasis_cache.c b/main/stasis_cache.c index ee9e56d837..a34e9bebda 100644 --- a/main/stasis_cache.c +++ b/main/stasis_cache.c @@ -176,7 +176,7 @@ static void cache_entry_dtor(void *obj) 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 99721ef3ca..627402697d 100644 --- a/main/stasis_message.c +++ b/main/stasis_message.c @@ -34,11 +34,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #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 = {}; @@ -75,6 +77,7 @@ int stasis_message_type_create(const char *name, ao2_cleanup(type); return STASIS_MESSAGE_TYPE_ERROR; } + type->hash = ast_hashtab_hash_string(name); type->vtable = vtable; *result = type; @@ -86,6 +89,11 @@ const char *stasis_message_type_name(const struct stasis_message_type *type) 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 */