return ERROR_OK;
}
+/* Avoid evaluating this each time we add a command. Reduces overhead from O(n^2) to O(n).
+ * Makes a difference on ARM7 types machines and is not observable on GHz machines.
+ */
+static int unique_length_dirty=1;
+
command_t* register_command(command_context_t *context, command_t *parent, char *name, int (*handler)(struct command_context_s *context, char* name, char** args, int argc), enum command_mode mode, char *help)
{
command_t *c, *p;
+ unique_length_dirty=1;
if (!context || !name)
return NULL;
}
}
- /* update unique lengths */
- build_unique_lengths(context, (parent) ? parent : context->commands);
-
return c;
}
int unregister_command(command_context_t *context, char *name)
{
+ unique_length_dirty=1;
+
command_t *c, *p = NULL, *c2;
if ((!context) || (!name))
{
command_t *c;
+ if (unique_length_dirty)
+ {
+ unique_length_dirty=0;
+ /* update unique lengths */
+ build_unique_lengths(context, context->commands);
+ }
+
for (c = commands; c; c = c->next)
{
if (strncasecmp(c->name, words[start_word], c->unique_len))