]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
stasis: Reduce calculation of stasis message type hash.
authorJoshua Colp <jcolp@digium.com>
Mon, 6 Aug 2018 11:36:22 +0000 (08:36 -0300)
committerJoshua Colp <jcolp@digium.com>
Mon, 6 Aug 2018 16:17:44 +0000 (11:17 -0500)
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

include/asterisk/stasis.h
main/stasis_cache.c
main/stasis_message.c

index 0373eeb35e7df7d74d6426f6da5fa7bb0388f21f..bca6d40259338084801b9888deca1e9b80cd652b 100644 (file)
@@ -318,6 +318,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
  *
index ca17bdd26388e6b13fabdaf8d520ac7f900b29dd..8c3c7f15b6648265488d941a1f1efa02229ecd93 100644 (file)
@@ -174,7 +174,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);
 }
 
index 88db49f1a63b2dbebc142b6850d588ff83c1afbf..482dd01d40a2bcfffe8b29aa3f96152e0bd2f829 100644 (file)
 #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 @@ 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;
 
@@ -84,6 +87,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 */