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
This commit is contained in:
Joshua Colp
2018-08-06 08:36:22 -03:00
parent db765cea68
commit 455ca1095e
3 changed files with 17 additions and 1 deletions

View File

@@ -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 @@ 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 */