diff --git a/ChangeLog b/ChangeLog index 841ff122..7ec6f7a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2014-04-26 Benno Schulenberg + * src/global.c (add_to_funcs): Add a pointer to the tail of the + functions list, to simplify and speed up adding new items. And + make use of it to remember the location of the Uncut item. + 2014-04-24 Benno Schulenberg * doc/faq.html: Update a few URLs, delete some obsolete ones, update the section on configuration flags and on translating nano, a whole diff --git a/src/global.c b/src/global.c index ee5cce2e..7e89b59b 100644 --- a/src/global.c +++ b/src/global.c @@ -167,9 +167,11 @@ int currmenu; /* The currently loaded menu. */ sc *sclist = NULL; - /* Struct for the shortcut-key list. */ + /* Pointer to the start of the shortcuts list. */ subnfunc *allfuncs = NULL; - /* Struct for the function list. */ + /* Pointer to the start of the functions list. */ +subnfunc *tailfunc; + /* Pointer to the last function in the list. */ subnfunc *uncutfunc; /* Pointer to the special Uncut/Unjustify item. */ @@ -284,17 +286,14 @@ function_type strtokeytype(const char *str) void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help, bool blank_after, bool viewok) { - subnfunc *f; + subnfunc *f = nmalloc(sizeof(subnfunc)); + + if (allfuncs == NULL) + allfuncs = f; + else + tailfunc->next = f; + tailfunc = f; - if (allfuncs == NULL) { - allfuncs = (subnfunc *) nmalloc(sizeof(subnfunc)); - f = allfuncs; - } else { - for (f = allfuncs; f->next != NULL; f = f->next) - ; - f->next = (subnfunc *)nmalloc(sizeof(subnfunc)); - f = f->next; - } f->next = NULL; f->scfunc = func; f->menus = menus; @@ -736,10 +735,8 @@ void shortcut_init(void) add_to_funcs(do_uncut_text, MMAIN, uncut_tag, IFSCHELP(nano_uncut_msg), FALSE, NOVIEW); - /* Remember the entry for Uncut, to be able to replace it with Unjustify. */ - for (uncutfunc = allfuncs; uncutfunc->next != NULL; uncutfunc = uncutfunc->next) - ; + uncutfunc = tailfunc; #ifndef NANO_TINY add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg),