[asterisk-commits] sorcery.c: Speed up ast sorcery retrieve by id() (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 11 20:12:55 CDT 2017


Anonymous Coward #1000019 has submitted this change and it was merged. ( https://gerrit.asterisk.org/5444 )

Change subject: sorcery.c: Speed up ast_sorcery_retrieve_by_id()
......................................................................


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
---
M main/sorcery.c
1 file changed, 8 insertions(+), 2 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/main/sorcery.c b/main/sorcery.c
index 51b0b22..0bb2826 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -1877,12 +1877,17 @@
 
 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;
 	}
 
@@ -1910,6 +1915,7 @@
 	}
 	AST_VECTOR_RW_UNLOCK(&object_type->wizards);
 
+	ao2_ref(object_type, -1);
 	return object;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/5444
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I871dbe162a301b5ced8b4393cec27180c7c6b218
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>



More information about the asterisk-commits mailing list