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

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


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


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/52/8052/1

diff --git a/main/loader.c b/main/loader.c
index 6119d63..f4e5f5a 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -58,6 +58,7 @@
 #include "asterisk/app.h"
 #include "asterisk/test.h"
 #include "asterisk/sounds_index.h"
+#include "asterisk/cli.h"
 
 #include <dlfcn.h>
 
@@ -771,12 +772,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;
@@ -804,14 +803,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);
@@ -820,8 +819,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, int _type)
@@ -837,7 +834,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/8052
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8bf51ffaa7ef1606f3bd1b5bb13f1905d72c6134
Gerrit-Change-Number: 8052
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/51ba4ef7/attachment.html>


More information about the asterisk-code-review mailing list