[Asterisk-code-review] loader: Use ast cli completion add for 'module load' complet... (asterisk[master])

Corey Farrell asteriskteam at digium.com
Thu Jan 25 12:06:27 CST 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/8050


Change subject: loader: Use ast_cli_completion_add for 'module load' completion.
......................................................................

loader: Use ast_cli_completion_add for 'module load' completion.

This should address potential performance issues with this completion
function.

Change-Id: I8bf51ffaa7ef1606f3bd1b5bb13f1905d72c6134
---
M main/loader.c
1 file changed, 8 insertions(+), 9 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/50/8050/1

diff --git a/main/loader.c b/main/loader.c
index da508f3..b973946 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -56,6 +56,7 @@
 #include "asterisk/app.h"
 #include "asterisk/test.h"
 #include "asterisk/sounds_index.h"
+#include "asterisk/cli.h"
 
 #include <dlfcn.h>
 
@@ -1036,12 +1037,10 @@
 	}
 }
 
-static char *module_load_helper(const char *word, int state)
+static void module_load_helper(const char *word)
 {
 	struct ast_module *mod;
-	int which = 0;
 	char *name;
-	char *ret = NULL;
 	char *editline_ret;
 	char fullpath[PATH_MAX];
 	int idx = 0;
@@ -1069,14 +1068,14 @@
 	 * The only way to avoid this would be to make a copy of the function
 	 * that skips matches found in the running_modules vector.
 	 */
-	while (!ret && (name = editline_ret = filename_completion_function(fullpath, idx++))) {
+	while ((name = editline_ret = filename_completion_function(fullpath, idx++))) {
 		if (word[0] != '/') {
 			name += (strlen(ast_config_AST_MODULE_DIR) + 1);
 		}
 
 		/* Don't list files that are already loaded! */
-		if (!AST_VECTOR_GET_CMP(&running_modules, name, !strcasecmp) && ++which > state) {
-			ret = ast_strdup(name);
+		if (!AST_VECTOR_GET_CMP(&running_modules, name, !strcasecmp)) {
+			ast_cli_completion_add(ast_strdup(name));
 		}
 
 		ast_std_free(editline_ret);
@@ -1085,8 +1084,6 @@
 	/* Do not clean-up the elements, they belong to module_list. */
 	AST_VECTOR_FREE(&running_modules);
 	AST_DLLIST_UNLOCK(&module_list);
-
-	return ret;
 }
 
 char *ast_module_helper(const char *line, const char *word, int pos, int state, int rpos, enum ast_module_helper_type type)
@@ -1101,7 +1098,9 @@
 	}
 
 	if (type == AST_MODULE_HELPER_LOAD) {
-		return module_load_helper(word, state);
+		module_load_helper(word);
+
+		return NULL;
 	}
 
 	if (type == AST_MODULE_HELPER_RELOAD) {

-- 
To view, visit https://gerrit.asterisk.org/8050
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8bf51ffaa7ef1606f3bd1b5bb13f1905d72c6134
Gerrit-Change-Number: 8050
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180125/c12613a6/attachment.html>


More information about the asterisk-code-review mailing list