- speed improvements for host and server lists
- fix plural form in reset_main_status_bar git-svn-id: http://svn.code.sf.net/p/xqf/code/trunk@330 d2ac09be-c843-0410-8b1f-f8a84130e0ec
This commit is contained in:
parent
eedd5573d0
commit
3f0797d6c2
@ -1,3 +1,7 @@
|
||||
Oct 27, 2002: Ludwig Nussel <l-n@users.sourceforge.net>
|
||||
- speed improvements for host and server lists
|
||||
- fix plural form in reset_main_status_bar
|
||||
|
||||
Oct 27, 2002: Alex <alex_b@users.sourceforge.net>
|
||||
- Number of servers in status bar now updated when enabling / disabling a
|
||||
filter and when finished searching for a player
|
||||
|
@ -127,6 +127,15 @@ if test "x$GCC" = xyes; then
|
||||
CFLAGS="$CFLAGS -Wall"
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(profiling,[ --enable-profiling compile with profiling (default=no)], enable_profile=yes, )
|
||||
AC_MSG_CHECKING(whether profiling is requested)
|
||||
if test x$enable_profile = xyes; then
|
||||
CFLAGS="$CFLAGS -pg"
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
AC_OUTPUT([Makefile intl/Makefile po/Makefile.in \
|
||||
src/Makefile src/xpm/Makefile \
|
||||
docs/Makefile
|
||||
|
@ -53,6 +53,16 @@ static int host_hash_func (const struct in_addr *ip) {
|
||||
return (ptr[0] + (ptr[1] << 2) + (ptr[2] << 4) + (ptr[3] << 6)) % hosts.num;
|
||||
}
|
||||
|
||||
static gint host_sorting_helper (const struct host *h1,
|
||||
const struct host *h2) {
|
||||
if(h1==h2)
|
||||
return 0;
|
||||
else if(h1<h2)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int hosts_total (void) {
|
||||
int i;
|
||||
@ -139,7 +149,7 @@ void host_unref (struct host *h) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
GSList *merge_host_to_resolve (GSList *hosts, struct host *h) {
|
||||
|
||||
if (h) {
|
||||
@ -149,7 +159,7 @@ GSList *merge_host_to_resolve (GSList *hosts, struct host *h) {
|
||||
|
||||
return hosts;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
GSList *merge_hosts_to_resolve (GSList *hosts, GSList *servers) {
|
||||
struct host *h;
|
||||
@ -158,8 +168,14 @@ GSList *merge_hosts_to_resolve (GSList *hosts, GSList *servers) {
|
||||
for (; servers; servers = servers->next) {
|
||||
h = ((struct server *) servers->data)->host;
|
||||
if (h->refreshed == 0 || h->refreshed >= curtime + HOST_CACHE_MAX_AGE)
|
||||
hosts = host_list_add (hosts, h);
|
||||
{
|
||||
// hosts = host_list_add (hosts, h);
|
||||
hosts = g_slist_prepend (hosts, h);
|
||||
host_ref(h);
|
||||
}
|
||||
}
|
||||
|
||||
hosts = slist_sort_remove_dups(hosts,host_sorting_helper,host_unref);
|
||||
|
||||
return hosts;
|
||||
}
|
||||
@ -178,7 +194,6 @@ static void host_cache_save_list (FILE *f, GSList *hosts) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static GSList *host_cache_read_list (FILE *f) {
|
||||
GSList *hosts = NULL;
|
||||
char buf[1024];
|
||||
@ -204,11 +219,15 @@ static GSList *host_cache_read_list (FILE *f) {
|
||||
h->name = g_strdup (token[2]);
|
||||
h->refreshed = refreshed;
|
||||
|
||||
hosts = host_list_add (hosts, h);
|
||||
// hosts = host_list_add (hosts, h);
|
||||
hosts = g_slist_prepend (hosts, h);
|
||||
host_ref(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hosts = slist_sort_remove_dups(hosts,host_sorting_helper,host_unref);
|
||||
|
||||
return hosts;
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ static struct master *read_list_parse_master (char *str, char *str2) {
|
||||
return m;
|
||||
}
|
||||
|
||||
static int server_sorting_helper (const struct server *s1,
|
||||
static gint server_sorting_helper (const struct server *s1,
|
||||
const struct server *s2) {
|
||||
if(s1==s2)
|
||||
return 0;
|
||||
@ -1237,46 +1237,6 @@ static void save_master_list (void) {
|
||||
config_pop_prefix ();
|
||||
}
|
||||
|
||||
// sort server list and remove duplicates
|
||||
static GSList* server_list_remove_dups(GSList* list)
|
||||
{
|
||||
int i;
|
||||
GSList* serverlist = NULL;
|
||||
GSList* serverlistnext = NULL;
|
||||
|
||||
if(!list)
|
||||
return NULL;
|
||||
|
||||
list = serverlist = g_slist_sort (list, (GCompareFunc) server_sorting_helper);
|
||||
|
||||
i = 0;
|
||||
while(serverlist)
|
||||
{
|
||||
serverlistnext=serverlist->next;
|
||||
if(!serverlistnext)
|
||||
{
|
||||
// last element, quit loop
|
||||
serverlist = serverlistnext;
|
||||
}
|
||||
else if(!server_sorting_helper(serverlist->data,serverlistnext->data))
|
||||
{
|
||||
struct server* s= serverlistnext->data;
|
||||
debug(1,"removing duplicate server %s",s->name);
|
||||
serverlistnext = g_slist_remove_link(serverlistnext, serverlistnext);
|
||||
serverlist->next = serverlistnext;
|
||||
server_unref(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
serverlist= serverlistnext;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
debug(2,"number of servers %d",i);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void init_masters (int update) {
|
||||
struct master *m;
|
||||
struct master *m2;
|
||||
@ -1318,7 +1278,7 @@ void init_masters (int update) {
|
||||
continue;
|
||||
debug (2, " Working on master: %s",m2->name);
|
||||
|
||||
m2->servers = server_list_remove_dups(m2->servers);
|
||||
m2->servers = slist_sort_remove_dups(m2->servers,(GCompareFunc)server_sorting_helper,server_unref);
|
||||
|
||||
}
|
||||
|
||||
|
@ -224,7 +224,10 @@ static int parse_master_output (char *str, struct stat_conn *conn) {
|
||||
o When the "conn" is freed, it will call the function
|
||||
to free the list returned here
|
||||
*/
|
||||
conn->servers = server_list_prepend (conn->servers, s);
|
||||
//XXX
|
||||
// conn->servers = server_list_prepend (conn->servers, s);
|
||||
conn->servers = g_slist_prepend (conn->servers, s);
|
||||
server_ref(s);
|
||||
}
|
||||
host_unref (h);
|
||||
}
|
||||
@ -232,7 +235,9 @@ static int parse_master_output (char *str, struct stat_conn *conn) {
|
||||
|
||||
g_strdown (addr);
|
||||
if ((us = userver_add (addr, port, type)) != NULL)
|
||||
conn->uservers = userver_list_add (conn->uservers, us);
|
||||
// conn->uservers = userver_list_add (conn->uservers, us);
|
||||
conn->uservers = g_slist_prepend (conn->uservers, us);
|
||||
userver_ref(s);
|
||||
}
|
||||
g_free (addr);
|
||||
}
|
||||
@ -1040,6 +1045,17 @@ static struct stat_conn *stat_open_conn_qstat (struct stat_job *job) {
|
||||
}
|
||||
|
||||
|
||||
// compare pointers
|
||||
static gint compare_ptr (gconstpointer s1, gconstpointer s2)
|
||||
{
|
||||
if(s1==s2)
|
||||
return 0;
|
||||
else if(s1<s2)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void stat_master_update_done (struct stat_conn *conn,
|
||||
struct stat_job *job,
|
||||
struct master *m,
|
||||
@ -1048,17 +1064,20 @@ static void stat_master_update_done (struct stat_conn *conn,
|
||||
|
||||
m->state = state;
|
||||
|
||||
debug (3, "stat_master_update_done(%s) -- status %d\n",
|
||||
debug (1, "stat_master_update_done(%s) -- status %d\n",
|
||||
(conn)? conn->master->name : "(null)", state);
|
||||
//XXX
|
||||
|
||||
if (state == SOURCE_UP && conn) {
|
||||
debug (3, "stat_master_update_done -- state == SOURCE_UP && conn");
|
||||
server_list_free (m->servers);
|
||||
m->servers = g_slist_reverse (conn->servers);
|
||||
// m->servers = g_slist_reverse (conn->servers);
|
||||
m->servers = slist_sort_remove_dups(conn->servers,compare_ptr,server_unref);
|
||||
conn->servers = NULL;
|
||||
|
||||
userver_list_free (m->uservers);
|
||||
m->uservers = g_slist_reverse (conn->uservers);
|
||||
// m->uservers = g_slist_reverse (conn->uservers);
|
||||
m->uservers = slist_sort_remove_dups(conn->uservers,compare_ptr,userver_unref);
|
||||
conn->uservers = NULL;
|
||||
|
||||
if (default_refresh_on_update)
|
||||
@ -1069,6 +1088,7 @@ static void stat_master_update_done (struct stat_conn *conn,
|
||||
stat_free_conn (conn);
|
||||
|
||||
job->need_redraw = TRUE;
|
||||
/*
|
||||
job->delayed.queued_servers = server_list_append_list (
|
||||
job->delayed.queued_servers, m->servers, UNKNOWN_SERVER);
|
||||
|
||||
@ -1076,6 +1096,25 @@ static void stat_master_update_done (struct stat_conn *conn,
|
||||
UNKNOWN_SERVER);
|
||||
job->names = userver_list_append_list (job->names, m->uservers,
|
||||
UNKNOWN_SERVER);
|
||||
*/
|
||||
for (tmp = m->servers; tmp; tmp = tmp->next)
|
||||
{
|
||||
job->delayed.queued_servers = g_slist_prepend(job->delayed.queued_servers, tmp->data);
|
||||
job->servers = g_slist_prepend(job->servers,tmp->data);
|
||||
server_ref(tmp->data);
|
||||
server_ref(tmp->data);
|
||||
}
|
||||
for (tmp = m->uservers; tmp; tmp = tmp->next)
|
||||
{
|
||||
job->names = g_slist_prepend(job->names,tmp->data);
|
||||
server_ref(tmp->data);
|
||||
}
|
||||
|
||||
job->delayed.queued_servers = slist_sort_remove_dups(job->delayed.queued_servers,compare_ptr,server_unref);
|
||||
|
||||
job->servers = slist_sort_remove_dups(job->servers,compare_ptr,server_unref);
|
||||
|
||||
job->names = slist_sort_remove_dups(job->names,compare_ptr,userver_unref);
|
||||
|
||||
debug (3, "stat_master_update_done -- job->master_handlers = %p",job->master_handlers);
|
||||
for (tmp = job->master_handlers; tmp; tmp = tmp->next)
|
||||
@ -1371,7 +1410,7 @@ static void stat_next (struct stat_job *job) {
|
||||
|
||||
if (job->servers) {
|
||||
|
||||
debug (3, "stat_next() -- Servers: Job %lx server list %lx", job, job->servers );
|
||||
debug (1, "Servers: Job %lx server list %lx", job, job->servers );
|
||||
if (!job->need_refresh) {
|
||||
stat_close (job, FALSE);
|
||||
return;
|
||||
@ -1388,7 +1427,7 @@ static void stat_next (struct stat_job *job) {
|
||||
if (!stat_open_conn_qstat (job)) {
|
||||
|
||||
/* It's very bad, stop everything. */
|
||||
debug (1, "job_next() -- Error! Could not stat_open_conn_qstat()");
|
||||
debug (0, "Error! Could not stat_open_conn_qstat()");
|
||||
stat_close (job, TRUE);
|
||||
}
|
||||
debug_decrease_indent();
|
||||
|
@ -618,3 +618,49 @@ char *find_game_dir (const char *basegamedir, const char *game, int *match_resul
|
||||
|
||||
return g_strdup (game);
|
||||
}
|
||||
|
||||
/** sort list and remove duplicates
|
||||
* @param list list to sort
|
||||
* @compare_func function to use for comparing
|
||||
* @unref_func function to call for each deleted entry
|
||||
* @return sorted list without duplicates
|
||||
*/
|
||||
GSList* slist_sort_remove_dups(GSList* list, GCompareFunc compare_func, void (*unref_func)(void*))
|
||||
{
|
||||
int i;
|
||||
GSList* serverlist = NULL;
|
||||
GSList* serverlistnext = NULL;
|
||||
|
||||
if(!list)
|
||||
return NULL;
|
||||
|
||||
list = serverlist = g_slist_sort (list, compare_func);
|
||||
|
||||
i = 0;
|
||||
while(serverlist)
|
||||
{
|
||||
serverlistnext=serverlist->next;
|
||||
if(!serverlistnext)
|
||||
{
|
||||
// last element, quit loop
|
||||
serverlist = serverlistnext;
|
||||
}
|
||||
else if(!compare_func(serverlist->data,serverlistnext->data))
|
||||
{
|
||||
GSList* dup = serverlistnext;
|
||||
serverlistnext = g_slist_remove_link(serverlistnext, dup);
|
||||
serverlist->next = serverlistnext;
|
||||
if(unref_func) unref_func(dup->data);
|
||||
g_slist_free_1(dup);
|
||||
}
|
||||
else
|
||||
{
|
||||
serverlist= serverlistnext;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
debug(2,"number of servers %d",i);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -81,4 +81,12 @@ int str2bool(const char* str);
|
||||
*/
|
||||
char* find_file_in_path(const char* files);
|
||||
|
||||
/** sort list and remove duplicates
|
||||
* @param list list to sort
|
||||
* @compare_func function to use for comparing
|
||||
* @unref_func function to call for each deleted entry
|
||||
* @return sorted list without duplicates
|
||||
*/
|
||||
GSList* slist_sort_remove_dups(GSList* list, GCompareFunc compare_func, void (*unref_func)(void*));
|
||||
|
||||
#endif /* __UTILS_H__ */
|
||||
|
@ -395,8 +395,9 @@ int check_qstat_version( const char* version )
|
||||
|
||||
void reset_main_status_bar() {
|
||||
// Reset bottom left status bar to show number of servers
|
||||
print_status (main_status_bar, (server_clist->rows == 1) ?
|
||||
_("%d server") : _("%d servers"), server_clist->rows);
|
||||
print_status (main_status_bar,
|
||||
ngettext(_("%d server"),_("%d servers"), server_clist->rows),
|
||||
server_clist->rows);
|
||||
}
|
||||
|
||||
void set_widgets_sensitivity (void) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user