mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
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
This commit is contained in:
@@ -1877,12 +1877,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)
|
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;
|
void *object = NULL;
|
||||||
int i;
|
int i;
|
||||||
unsigned int cached = 0;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1910,6 +1915,7 @@ void *ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *
|
|||||||
}
|
}
|
||||||
AST_VECTOR_RW_UNLOCK(&object_type->wizards);
|
AST_VECTOR_RW_UNLOCK(&object_type->wizards);
|
||||||
|
|
||||||
|
ao2_ref(object_type, -1);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user