Browse Source

Optimiation for proxy commands cleaning.

git-svn-id: https://klish.googlecode.com/svn/trunk@185 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
9eb3d9385a
1 changed files with 8 additions and 7 deletions
  1. 8 7
      clish/nspace/nspace.c

+ 8 - 7
clish/nspace/nspace.c

@@ -77,6 +77,7 @@ static clish_command_t *clish_nspace_find_create_command(clish_nspace_t * this,
 	char *name = NULL;
 	clish_command_t *tmp = NULL;
 	lub_bintree_iterator_t iter;
+	const char *str = NULL;
 
 	assert(prefix);
 	if (!ref) {
@@ -101,13 +102,13 @@ static clish_command_t *clish_nspace_find_create_command(clish_nspace_t * this,
 
 	/* Delete proxy commands with another prefixes */
 	tmp = lub_bintree_findfirst(&this->tree);
-	for(lub_bintree_iterator_init(&iter, &this->tree, tmp);
-		tmp; tmp = lub_bintree_iterator_next(&iter)) {
-		const char *str = clish_command__get_name(tmp);
-		if (lub_string_nocasestr(str, prefix) == str)
-			continue;
-		lub_bintree_remove(&this->tree, tmp);
-		clish_command_delete(tmp);
+	if (tmp)
+		str = clish_command__get_name(tmp);
+	if (str && (lub_string_nocasestr(str, prefix) != str)) {
+		do {
+			lub_bintree_remove(&this->tree, tmp);
+			clish_command_delete(tmp);
+		} while ((tmp = lub_bintree_findfirst(&this->tree)));
 	}
 
 	/* Insert command link into the tree */