<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7501">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Sean Bright: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">loader: Refactor resource_name_match.<br><br>Optimize resource_name_match. This change eliminates use of<br>ast_strdupa, instead verifying that both basename's are the same length,<br>then using strncasecmp.<br><br>Change-Id: I477275c0e954c99d74be5abfc8bb6545b04e5a3d<br>---<br>M main/loader.c<br>1 file changed, 29 insertions(+), 18 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/loader.c b/main/loader.c<br>index 2238975..49151cc 100644<br>--- a/main/loader.c<br>+++ b/main/loader.c<br>@@ -376,35 +376,39 @@<br> return -1;<br> }<br> <br>-static int resource_name_match(const char *name1_in, const char *name2_in)<br>+static size_t resource_name_baselen(const char *name)<br> {<br>- char *name1 = (char *) name1_in;<br>- char *name2 = (char *) name2_in;<br>+ size_t len = strlen(name);<br> <br>- /* trim off any .so extensions */<br>- if (!strcasecmp(name1 + strlen(name1) - 3, ".so")) {<br>- name1 = ast_strdupa(name1);<br>- name1[strlen(name1) - 3] = '\0';<br>- }<br>- if (!strcasecmp(name2 + strlen(name2) - 3, ".so")) {<br>- name2 = ast_strdupa(name2);<br>- name2[strlen(name2) - 3] = '\0';<br>+ if (len > 3 && !strcasecmp(name + len - 3, ".so")) {<br>+ return len - 3;<br> }<br> <br>- return strcasecmp(name1, name2);<br>+ return len;<br>+}<br>+<br>+static int resource_name_match(const char *name1, size_t baselen1, const char *name2)<br>+{<br>+ if (baselen1 != resource_name_baselen(name2)) {<br>+ return -1;<br>+ }<br>+<br>+ return strncasecmp(name1, name2, baselen1);<br> }<br> <br> static struct ast_module *find_resource(const char *resource, int do_lock)<br> {<br> struct ast_module *cur;<br>+ size_t resource_baselen = resource_name_baselen(resource);<br> <br> if (do_lock) {<br> AST_DLLIST_LOCK(&module_list);<br> }<br> <br> AST_DLLIST_TRAVERSE(&module_list, cur, entry) {<br>- if (!resource_name_match(resource, cur->resource))<br>+ if (!resource_name_match(resource, resource_baselen, cur->resource)) {<br> break;<br>+ }<br> }<br> <br> if (do_lock) {<br>@@ -938,6 +942,7 @@<br> struct ast_module *cur;<br> enum ast_module_reload_result res = AST_MODULE_RELOAD_NOT_FOUND;<br> int i;<br>+ size_t name_baselen = name ? resource_name_baselen(name) : 0;<br> <br> /* If we aren't fully booted, we just pretend we reloaded but we queue this<br> up to run once we are booted up. */<br>@@ -991,8 +996,9 @@<br> AST_DLLIST_TRAVERSE(&module_list, cur, entry) {<br> const struct ast_module_info *info = cur->info;<br> <br>- if (name && resource_name_match(name, cur->resource))<br>+ if (name && resource_name_match(name, name_baselen, cur->resource)) {<br> continue;<br>+ }<br> <br> if (!cur->flags.running || cur->flags.declined) {<br> if (res == AST_MODULE_RELOAD_NOT_FOUND) {<br>@@ -1186,9 +1192,10 @@<br> static struct load_order_entry *add_to_load_order(const char *resource, struct load_order *load_order, int required)<br> {<br> struct load_order_entry *order;<br>+ size_t resource_baselen = resource_name_baselen(resource);<br> <br> AST_LIST_TRAVERSE(load_order, order, entry) {<br>- if (!resource_name_match(order->resource, resource)) {<br>+ if (!resource_name_match(resource, resource_baselen, order->resource)) {<br> /* Make sure we have the proper setting for the required field<br> (we might have both load= and required= lines in modules.conf) */<br> order->required |= required;<br>@@ -1435,11 +1442,15 @@<br> /* now scan the config for any modules we are prohibited from loading and<br> remove them from the load order */<br> for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) {<br>- if (strcasecmp(v->name, "noload"))<br>- continue;<br>+ size_t baselen;<br> <br>+ if (strcasecmp(v->name, "noload")) {<br>+ continue;<br>+ }<br>+<br>+ baselen = resource_name_baselen(v->value);<br> AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {<br>- if (!resource_name_match(order->resource, v->value)) {<br>+ if (!resource_name_match(v->value, baselen, order->resource)) {<br> AST_LIST_REMOVE_CURRENT(entry);<br> ast_free(order->resource);<br> ast_free(order);<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7501">change 7501</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/7501"/><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: I477275c0e954c99d74be5abfc8bb6545b04e5a3d </div>
<div style="display:none"> Gerrit-Change-Number: 7501 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: 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: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>