]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
sorcery.c: Speed up ast_sorcery_retrieve_by_id()
authorRichard Mudgett <rmudgett@digium.com>
Thu, 6 Apr 2017 23:30:11 +0000 (18:30 -0500)
committerRichard Mudgett <rmudgett@digium.com>
Tue, 11 Apr 2017 18:00:06 +0000 (13:00 -0500)
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

main/sorcery.c

index 9f8c35c3b9e174a449251f87bd89a995547f4ffa..5d0b38ff544814887e95a60b39187378bc7c410e 100644 (file)
@@ -1879,12 +1879,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;
        }
 
@@ -1912,6 +1917,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;
 }