diff options
author | Richard Mudgett <rmudgett@digium.com> | 2017-04-06 18:30:11 -0500 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2017-04-11 13:03:57 -0500 |
commit | 19b82a864415f57c72fa939f0909622761d3b358 (patch) | |
tree | da36a687fbeadedbb5a011eb0266a38192f14a05 | |
parent | aecf19e7d26c4198906d4e9a75ba955acb26e6b5 (diff) |
sorcery.c: Speed up ast_sorcery_retrieve_by_id()
Return early if ast_sorcery_retrieve_by_id() is not passed an id to find.
Also eliminated the RAII_VAR() usage in the function.
Change-Id: I871dbe162a301b5ced8b4393cec27180c7c6b218
-rw-r--r-- | main/sorcery.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/main/sorcery.c b/main/sorcery.c index f96e06ece..713b038e6 100644 --- a/main/sorcery.c +++ b/main/sorcery.c @@ -1858,12 +1858,17 @@ static int sorcery_cache_create(void *obj, void *arg, int flags) void *ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id) { - RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup); + struct ast_sorcery_object_type *object_type; void *object = NULL; int i; unsigned int cached = 0; - if (!object_type || ast_strlen_zero(id)) { + if (ast_strlen_zero(id)) { + return NULL; + } + + object_type = ao2_find(sorcery->types, type, OBJ_SEARCH_KEY); + if (!object_type) { return NULL; } @@ -1891,6 +1896,7 @@ void *ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char * } AST_VECTOR_RW_UNLOCK(&object_type->wizards); + ao2_ref(object_type, -1); return object; } |