commit 20b1e92857777fe6e725682f526189e54006bf7b
parent 67e1387f044f2f13b3fee0d42b85065e80b4fec4
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Sat, 26 Apr 2014 18:41:43 +0000
Add a pointer to the tail of the functions list,
to simplify and speed up adding new items.
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4815 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
2 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,8 @@
+2014-04-26 Benno Schulenberg <bensberg@justemail.net>
+ * 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 <bensberg@justemail.net>
* 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
@@ -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),