<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7243">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Use sorcery prefix operation for contact lookup<br><br>This improves performance for registrations assuming that<br>res_config_astdb is not in use.<br><br>Change-Id: I86f37aa9ef07a4fe63448cb881bbadd996834bb1<br>---<br>M res/res_pjsip/location.c<br>1 file changed, 10 insertions(+), 9 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/43/7243/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c<br>index 0d7b3da..299fdb7 100644<br>--- a/res/res_pjsip/location.c<br>+++ b/res/res_pjsip/location.c<br>@@ -82,16 +82,17 @@<br> {<br> const struct ast_sip_aor *aor = object;<br> const char *aor_id = ast_sorcery_object_get_id(object);<br>- /* Give enough space for ^ at the beginning and ;@ at the end, since that is our object naming scheme */<br>- char regex[strlen(aor_id) + 4];<br>+ /* Give enough space for ;@ at the end, since that is our object naming scheme */<br>+ size_t prefix_len = strlen(aor_id) + sizeof(";@") - 1;<br>+ char prefix[prefix_len + 1];<br> struct ao2_container *contacts;<br> <br> if (aor->permanent_contacts) {<br> ao2_callback(aor->permanent_contacts, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, destroy_contact, NULL);<br> }<br> <br>- snprintf(regex, sizeof(regex), "^%s;@", aor_id);<br>- if (!(contacts = ast_sorcery_retrieve_by_regex(ast_sip_get_sorcery(), "contact", regex))) {<br>+ sprintf(prefix, "%s;@", aor_id); /* Safe */<br>+ if (!(contacts = ast_sorcery_retrieve_by_prefix(ast_sip_get_sorcery(), "contact", prefix, prefix_len))) {<br> return;<br> }<br> /* Destroy any contacts that may still exist that were made for this AoR */<br>@@ -223,13 +224,13 @@<br> struct ao2_container *ast_sip_location_retrieve_aor_contacts_nolock_filtered(const struct ast_sip_aor *aor,<br> unsigned int flags)<br> {<br>- /* Give enough space for ^ at the beginning and ;@ at the end, since that is our object naming scheme */<br>- char regex[strlen(ast_sorcery_object_get_id(aor)) + 4];<br>+ /* Give enough space for ;@ at the end, since that is our object naming scheme */<br>+ size_t prefix_len = strlen(ast_sorcery_object_get_id(aor)) + sizeof(";@") - 1;<br>+ char prefix[prefix_len + 1];<br> struct ao2_container *contacts;<br> <br>- snprintf(regex, sizeof(regex), "^%s;@", ast_sorcery_object_get_id(aor));<br>-<br>- if (!(contacts = ast_sorcery_retrieve_by_regex(ast_sip_get_sorcery(), "contact", regex))) {<br>+ sprintf(prefix, "%s;@", ast_sorcery_object_get_id(aor)); /* Safe */<br>+ if (!(contacts = ast_sorcery_retrieve_by_prefix(ast_sip_get_sorcery(), "contact", prefix, prefix_len))) {<br> return NULL;<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7243">change 7243</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/7243"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I86f37aa9ef07a4fe63448cb881bbadd996834bb1 </div>
<div style="display:none"> Gerrit-Change-Number: 7243 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>