[Asterisk-code-review] res stasis device state.c: Optimize stasis app device states... (asterisk[master])

Joshua Colp asteriskteam at digium.com
Mon Nov 6 05:28:28 CST 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/6977 )

Change subject: res_stasis_device_state.c: Optimize stasis_app_device_states_to_json()
......................................................................

res_stasis_device_state.c: Optimize stasis_app_device_states_to_json()

* Eliminate RAII_VAR()
* Replace looped alloca with a char[] since that is how it is used anyway.

Change-Id: Ia27e64a884afa0f50b9ffdb1cf23da6bfa51ffdf
---
M res/res_stasis_device_state.c
1 file changed, 10 insertions(+), 10 deletions(-)

Approvals:
  Sean Bright: Looks good to me, but someone else must approve
  Corey Farrell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



diff --git a/res/res_stasis_device_state.c b/res/res_stasis_device_state.c
index 276a98b..6527af4 100644
--- a/res/res_stasis_device_state.c
+++ b/res/res_stasis_device_state.c
@@ -168,22 +168,22 @@
 struct ast_json *stasis_app_device_states_to_json(void)
 {
 	struct ast_json *array = ast_json_array_create();
-	RAII_VAR(struct ast_db_entry *, tree,
-		 ast_db_gettree(DEVICE_STATE_FAMILY, NULL), ast_db_freetree);
+	struct ast_db_entry *tree;
 	struct ast_db_entry *entry;
 
+	tree = ast_db_gettree(DEVICE_STATE_FAMILY, NULL);
 	for (entry = tree; entry; entry = entry->next) {
 		const char *name = strrchr(entry->key, '/');
+
 		if (!ast_strlen_zero(name)) {
-			struct ast_str *device = ast_str_alloca(DEVICE_STATE_SIZE);
-			ast_str_set(&device, 0, "%s%s",
-				    DEVICE_STATE_SCHEME_STASIS, ++name);
-			ast_json_array_append(
-				array, stasis_app_device_state_to_json(
-					ast_str_buffer(device),
-					ast_device_state(ast_str_buffer(device))));
+			char device[DEVICE_STATE_SIZE];
+
+			snprintf(device, sizeof(device), "%s%s", DEVICE_STATE_SCHEME_STASIS, ++name);
+			ast_json_array_append(array,
+				stasis_app_device_state_to_json(device, ast_device_state(device)));
 		}
 	}
+	ast_db_freetree(tree);
 
 	return array;
 }
@@ -291,7 +291,7 @@
 
 static enum ast_device_state stasis_device_state_cb(const char *data)
 {
-	char buf[DEVICE_STATE_SIZE] = "";
+	char buf[DEVICE_STATE_SIZE];
 
 	ast_db_get(DEVICE_STATE_FAMILY, data, buf, sizeof(buf));
 

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia27e64a884afa0f50b9ffdb1cf23da6bfa51ffdf
Gerrit-Change-Number: 6977
Gerrit-PatchSet: 2
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171106/c88e5d06/attachment.html>


More information about the asterisk-code-review mailing list