From 03886fc7d06f1414a55b918247ba0310ab16e41c Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 21 Feb 2013 18:37:06 +0000 Subject: Keep settings lists sorted. It's already sorted somewhat, but in unclearly divided fragments. The lists are getting long enough in places that having sections would help. That's more work, just sorting is a good start. --- set.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'set.c') diff --git a/set.c b/set.c index a1eb9f03..537143f7 100644 --- a/set.c +++ b/set.c @@ -1,7 +1,7 @@ /********************************************************************\ * BitlBee -- An IRC to other IM-networks gateway * * * - * Copyright 2002-2005 Wilmer van der Gaast and others * + * Copyright 2002-2013 Wilmer van der Gaast and others * \********************************************************************/ /* Some stuff to register, handle and save user preferences */ @@ -22,6 +22,7 @@ if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #define BITLBEE_CORE #include "bitlbee.h" @@ -38,9 +39,22 @@ set_t *set_add( set_t **head, const char *key, const char *def, set_eval eval, v { if( ( s = *head ) ) { - while( s->next ) s = s->next; - s->next = g_new0( set_t, 1 ); - s = s->next; + /* Sorted insertion. Special-case insertion at the start. */ + if( strcmp( key, s->key ) < 0 ) + { + s = g_new0( set_t, 1 ); + s->next = *head; + *head = s; + } + else + { + while( s->next && strcmp( key, s->next->key ) > 0 ) + s = s->next; + set_t *last_next = s->next; + s->next = g_new0( set_t, 1 ); + s = s->next; + s->next = last_next; + } } else { -- cgit v1.2.3