[Asterisk-code-review] sorcery.c: Minor optimizations. (asterisk[14])

Richard Mudgett asteriskteam at digium.com
Thu Aug 11 12:20:42 CDT 2016


Richard Mudgett has uploaded a new change for review.

  https://gerrit.asterisk.org/3496

Change subject: sorcery.c: Minor optimizations.
......................................................................

sorcery.c: Minor optimizations.

* Remove some unused parameters from internal functions:
sorcery_wizard_create()
sorcery_wizard_update()
sorcery_wizard_delete()

* Created the struct sorcery_observer_invocation ao2 object without a lock
since it is not needed in sorcery_observer_invocation_alloc().

Change-Id: Iff71d75f52bc1b8cee955456838c149faaa4f92e
---
M main/sorcery.c
1 file changed, 21 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/96/3496/1

diff --git a/main/sorcery.c b/main/sorcery.c
index 1fb1b3c..328c419 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -1352,8 +1352,10 @@
 /*! \brief Allocator function for observer invocation */
 static struct sorcery_observer_invocation *sorcery_observer_invocation_alloc(struct ast_sorcery_object_type *object_type, void *object)
 {
-	struct sorcery_observer_invocation *invocation = ao2_alloc(sizeof(*invocation), sorcery_observer_invocation_destroy);
+	struct sorcery_observer_invocation *invocation;
 
+	invocation = ao2_alloc_options(sizeof(*invocation),
+		sorcery_observer_invocation_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
 	if (!invocation) {
 		return NULL;
 	}
@@ -1978,11 +1980,8 @@
 }
 
 /*! \brief Internal function which returns if the wizard has created the object */
-static int sorcery_wizard_create(void *obj, void *arg, int flags)
+static int sorcery_wizard_create(const struct ast_sorcery_object_wizard *object_wizard, const struct sorcery_details *details)
 {
-	const struct ast_sorcery_object_wizard *object_wizard = obj;
-	const struct sorcery_details *details = arg;
-
 	if (!object_wizard->wizard->callbacks.create) {
 		ast_debug(5, "Sorcery wizard '%s' does not support creation\n", object_wizard->wizard->callbacks.name);
 		return 0;
@@ -2037,7 +2036,8 @@
 	AST_VECTOR_RW_RDLOCK(&object_type->wizards);
 	for (i = 0; i < AST_VECTOR_SIZE(&object_type->wizards); i++) {
 		found_wizard = AST_VECTOR_GET(&object_type->wizards, i);
-		if (!found_wizard->caching && sorcery_wizard_create(found_wizard, &sdetails, 0) == CMP_MATCH) {
+		if (!found_wizard->caching
+			&& sorcery_wizard_create(found_wizard, &sdetails) == CMP_MATCH) {
 			object_wizard = found_wizard;
 		}
 	}
@@ -2046,14 +2046,14 @@
 		for (i = 0; i < AST_VECTOR_SIZE(&object_type->wizards); i++) {
 			found_wizard = AST_VECTOR_GET(&object_type->wizards, i);
 			if (found_wizard->caching) {
-				sorcery_wizard_create(found_wizard, &sdetails, 0);
+				sorcery_wizard_create(found_wizard, &sdetails);
 			}
 		}
 
 		if (ao2_container_count(object_type->observers)) {
-			struct sorcery_observer_invocation *invocation = sorcery_observer_invocation_alloc(
-				object_type, object);
+			struct sorcery_observer_invocation *invocation;
 
+			invocation = sorcery_observer_invocation_alloc(object_type, object);
 			if (invocation
 				&& ast_taskprocessor_push(object_type->serializer, sorcery_observers_notify_create,
 					invocation)) {
@@ -2091,11 +2091,8 @@
 }
 
 /*! \brief Internal function which returns if a wizard has updated the object */
-static int sorcery_wizard_update(void *obj, void *arg, int flags)
+static int sorcery_wizard_update(const struct ast_sorcery_object_wizard *object_wizard, const struct sorcery_details *details)
 {
-	const struct ast_sorcery_object_wizard *object_wizard = obj;
-	const struct sorcery_details *details = arg;
-
 	if (!object_wizard->wizard->callbacks.update) {
 		ast_debug(5, "Sorcery wizard '%s' does not support updating\n", object_wizard->wizard->callbacks.name);
 		return 0;
@@ -2127,7 +2124,8 @@
 	AST_VECTOR_RW_RDLOCK(&object_type->wizards);
 	for (i = 0; i < AST_VECTOR_SIZE(&object_type->wizards); i++) {
 		found_wizard = AST_VECTOR_GET(&object_type->wizards, i);
-		if (!found_wizard->caching && sorcery_wizard_update(found_wizard, &sdetails, 0) == CMP_MATCH) {
+		if (!found_wizard->caching
+			&& sorcery_wizard_update(found_wizard, &sdetails) == CMP_MATCH) {
 			object_wizard = found_wizard;
 		}
 	}
@@ -2136,14 +2134,14 @@
 		for (i = 0; i < AST_VECTOR_SIZE(&object_type->wizards); i++) {
 			found_wizard = AST_VECTOR_GET(&object_type->wizards, i);
 			if (found_wizard->caching) {
-				sorcery_wizard_update(found_wizard, &sdetails, 0);
+				sorcery_wizard_update(found_wizard, &sdetails);
 			}
 		}
 
 		if (ao2_container_count(object_type->observers)) {
-			struct sorcery_observer_invocation *invocation = sorcery_observer_invocation_alloc(
-				object_type, object);
+			struct sorcery_observer_invocation *invocation;
 
+			invocation = sorcery_observer_invocation_alloc(object_type, object);
 			if (invocation
 				&& ast_taskprocessor_push(object_type->serializer, sorcery_observers_notify_update,
 					invocation)) {
@@ -2181,11 +2179,8 @@
 }
 
 /*! \brief Internal function which returns if a wizard has deleted the object */
-static int sorcery_wizard_delete(void *obj, void *arg, int flags)
+static int sorcery_wizard_delete(const struct ast_sorcery_object_wizard *object_wizard, const struct sorcery_details *details)
 {
-	const struct ast_sorcery_object_wizard *object_wizard = obj;
-	const struct sorcery_details *details = arg;
-
 	if (!object_wizard->wizard->callbacks.delete) {
 		ast_debug(5, "Sorcery wizard '%s' does not support deletion\n", object_wizard->wizard->callbacks.name);
 		return 0;
@@ -2217,7 +2212,8 @@
 	AST_VECTOR_RW_RDLOCK(&object_type->wizards);
 	for (i = 0; i < AST_VECTOR_SIZE(&object_type->wizards); i++) {
 		found_wizard = AST_VECTOR_GET(&object_type->wizards, i);
-		if (!found_wizard->caching && sorcery_wizard_delete(found_wizard, &sdetails, 0) == CMP_MATCH) {
+		if (!found_wizard->caching
+			&& sorcery_wizard_delete(found_wizard, &sdetails) == CMP_MATCH) {
 			object_wizard = found_wizard;
 		}
 	}
@@ -2226,14 +2222,14 @@
 		for (i = 0; i < AST_VECTOR_SIZE(&object_type->wizards); i++) {
 			found_wizard = AST_VECTOR_GET(&object_type->wizards, i);
 			if (found_wizard->caching) {
-				sorcery_wizard_delete(found_wizard, &sdetails, 0);
+				sorcery_wizard_delete(found_wizard, &sdetails);
 			}
 		}
 
 		if (ao2_container_count(object_type->observers)) {
-			struct sorcery_observer_invocation *invocation = sorcery_observer_invocation_alloc(
-				object_type, object);
+			struct sorcery_observer_invocation *invocation;
 
+			invocation = sorcery_observer_invocation_alloc(object_type, object);
 			if (invocation
 				&& ast_taskprocessor_push(object_type->serializer, sorcery_observers_notify_delete,
 					invocation)) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff71d75f52bc1b8cee955456838c149faaa4f92e
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-code-review mailing list