<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/6977">View Change</a></p><div style="white-space:pre-wrap">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
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_stasis_device_state.c: Optimize stasis_app_device_states_to_json()<br><br>* Eliminate RAII_VAR()<br>* Replace looped alloca with a char[] since that is how it is used anyway.<br><br>Change-Id: Ia27e64a884afa0f50b9ffdb1cf23da6bfa51ffdf<br>---<br>M res/res_stasis_device_state.c<br>1 file changed, 10 insertions(+), 10 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_stasis_device_state.c b/res/res_stasis_device_state.c<br>index 276a98b..6527af4 100644<br>--- a/res/res_stasis_device_state.c<br>+++ b/res/res_stasis_device_state.c<br>@@ -168,22 +168,22 @@<br> struct ast_json *stasis_app_device_states_to_json(void)<br> {<br> struct ast_json *array = ast_json_array_create();<br>- RAII_VAR(struct ast_db_entry *, tree,<br>- ast_db_gettree(DEVICE_STATE_FAMILY, NULL), ast_db_freetree);<br>+ struct ast_db_entry *tree;<br> struct ast_db_entry *entry;<br> <br>+ tree = ast_db_gettree(DEVICE_STATE_FAMILY, NULL);<br> for (entry = tree; entry; entry = entry->next) {<br> const char *name = strrchr(entry->key, '/');<br>+<br> if (!ast_strlen_zero(name)) {<br>- struct ast_str *device = ast_str_alloca(DEVICE_STATE_SIZE);<br>- ast_str_set(&device, 0, "%s%s",<br>- DEVICE_STATE_SCHEME_STASIS, ++name);<br>- ast_json_array_append(<br>- array, stasis_app_device_state_to_json(<br>- ast_str_buffer(device),<br>- ast_device_state(ast_str_buffer(device))));<br>+ char device[DEVICE_STATE_SIZE];<br>+<br>+ snprintf(device, sizeof(device), "%s%s", DEVICE_STATE_SCHEME_STASIS, ++name);<br>+ ast_json_array_append(array,<br>+ stasis_app_device_state_to_json(device, ast_device_state(device)));<br> }<br> }<br>+ ast_db_freetree(tree);<br> <br> return array;<br> }<br>@@ -291,7 +291,7 @@<br> <br> static enum ast_device_state stasis_device_state_cb(const char *data)<br> {<br>- char buf[DEVICE_STATE_SIZE] = "";<br>+ char buf[DEVICE_STATE_SIZE];<br> <br> ast_db_get(DEVICE_STATE_FAMILY, data, buf, sizeof(buf));<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6977">change 6977</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/6977"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ia27e64a884afa0f50b9ffdb1cf23da6bfa51ffdf </div>
<div style="display:none"> Gerrit-Change-Number: 6977 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>