<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7503">View Change</a></p><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;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/03/7503/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/loader.c b/main/loader.c<br>index 7d792b0..b1a02d5 100644<br>--- a/main/loader.c<br>+++ b/main/loader.c<br>@@ -382,35 +382,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>@@ -947,6 +951,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>@@ -1000,8 +1005,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>@@ -1195,9 +1201,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>@@ -1444,11 +1451,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/7503">change 7503</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/7503"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I477275c0e954c99d74be5abfc8bb6545b04e5a3d </div>
<div style="display:none"> Gerrit-Change-Number: 7503 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>