summaryrefslogtreecommitdiff
path: root/res/res_stasis_device_state.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2017-11-01 18:04:31 -0500
committerRichard Mudgett <rmudgett@digium.com>2017-11-03 12:43:11 -0500
commitde4a4796d0e886bf7e32ad828d9a387714bda98b (patch)
tree372d9542f0b227a26b9361385eeac16c71e79a01 /res/res_stasis_device_state.c
parent325b5dd30fe5ede5326ed96b448ee61dd5a51c2f (diff)
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
Diffstat (limited to 'res/res_stasis_device_state.c')
-rw-r--r--res/res_stasis_device_state.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/res/res_stasis_device_state.c b/res/res_stasis_device_state.c
index 276a98b93..6527af4a6 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_state_to_json(
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 void populate_cache(void)
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));