aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2010-08-18 05:23:19 +0100
committerRobert Bragg <robert@linux.intel.com>2010-08-18 05:23:19 +0100
commit87a442284756c90e58bf24c01052d7d8f04c83ee (patch)
treeb048f98b8c67410582984139b70799170d91c7b7
parent9cd5388ae2e3044bd916d56b80217ff20dc3c589 (diff)
downloadlibmatchboxwm2-87a442284756c90e58bf24c01052d7d8f04c83ee.tar.gz
libmatchboxwm2-87a442284756c90e58bf24c01052d7d8f04c83ee.tar.bz2
libmatchboxwm2-87a442284756c90e58bf24c01052d7d8f04c83ee.zip
util: re-implement linked lists using GList API
This makes the mb_wm_util_list API pass straight through to the g_list API.
-rw-r--r--matchbox/mb-wm-util.c136
-rw-r--r--matchbox/mb-wm-util.h3
2 files changed, 12 insertions, 127 deletions
diff --git a/matchbox/mb-wm-util.c b/matchbox/mb-wm-util.c
index f99777c..9bf5b99 100644
--- a/matchbox/mb-wm-util.c
+++ b/matchbox/mb-wm-util.c
@@ -1,6 +1,8 @@
#include "mb-wm-config.h"
#include "mb-wm-util.h"
+#include <glib.h>
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -39,18 +41,7 @@ mb_wm_util_untrap_x_errors(void)
void*
mb_wm_util_malloc0(int size)
{
- void *p = NULL;
-
- p = malloc(size);
-
- if (p == NULL)
- {
- /* hook into some kind of out of memory */
- }
- else
- memset(p, 0, size);
-
- return p;
+ return g_malloc0 (size);
}
Bool /* FIXME: define, inline ? */
@@ -97,135 +88,46 @@ mb_wm_util_warn (const char *format, ...)
if (msg) free(msg);
}
-MBWMList*
-mb_wm_util_list_alloc_item(void)
-{
- return mb_wm_util_malloc0(sizeof(MBWMList));
-}
-
int
mb_wm_util_list_length(MBWMList *list)
{
- int result = 1;
-
- if (!list)
- return 0;
-
- list = mb_wm_util_list_get_first(list);
-
- while ((list = mb_wm_util_list_next(list)) != NULL)
- result++;
-
- return result;
+ return g_list_length ((GList *)list);
}
MBWMList*
mb_wm_util_list_get_last(MBWMList *list)
{
- if (list == NULL)
- return NULL;
-
- while (list->next)
- list = mb_wm_util_list_next(list);
- return list;
+ return (MBWMList *)g_list_last ((GList *)list);
}
MBWMList*
mb_wm_util_list_get_first(MBWMList *list)
{
- if (list == NULL)
- return NULL;
-
- while (list->prev)
- list = mb_wm_util_list_prev(list);
- return list;
+ return (MBWMList *)g_list_first ((GList *)list);
}
void*
mb_wm_util_list_get_nth_data(MBWMList *list, int n)
{
- if (list == NULL)
- return NULL;
-
- list = mb_wm_util_list_get_first(list);
-
- while (list->next && n)
- {
- list = mb_wm_util_list_next(list);
- n--;
- }
-
- if (n) return NULL;
-
- return (void *)list->data;
+ return g_list_nth_data ((GList *)list, n);
}
MBWMList*
mb_wm_util_list_prepend(MBWMList *list, void *data)
{
- MBWMList * l = mb_wm_util_list_alloc_item();
-
- l->data = data;
- l->next = list;
-
- if (list)
- list->prev = l;
-
- return l;
+ return (MBWMList *)g_list_prepend ((GList *)list, data);
}
MBWMList*
mb_wm_util_list_append(MBWMList *list, void *data)
{
- if (list == NULL)
- {
- list = mb_wm_util_list_alloc_item();
- list->data = data;
- }
- else
- {
- MBWMList *last;
-
- last = mb_wm_util_list_get_last(list);
-
- last->next = mb_wm_util_list_alloc_item();
- last->next->prev = last;
- last->next->data = data;
- }
-
- return list;
+ return (MBWMList *)g_list_append ((GList *)list, data);
}
MBWMList*
mb_wm_util_list_remove(MBWMList *list, void *data)
{
- MBWMList *prev, *start;
-
- prev = NULL;
- start = list = mb_wm_util_list_get_first(list);
-
- while (list)
- {
- if (list->data == data)
- {
- if (list->next)
- list->next->prev = prev;
-
- if (prev)
- prev->next = list->next;
- else
- start = list->next;
-
- free(list);
-
- return start;
- }
-
- prev = list;
- list = list->next;
- }
-
- return NULL;
+ return (MBWMList *)g_list_remove ((GList *)list, data);
}
void
@@ -233,27 +135,13 @@ mb_wm_util_list_foreach (const MBWMList *list,
MBWMListForEachCB func,
void *userdata)
{
- MBWMList *p = (MBWMList *) list;
-
- while (p)
- {
- func(p->data, userdata);
- p = mb_wm_util_list_next(p);
- }
+ g_list_foreach ((GList *)list, (GFunc)func, userdata);
}
void
mb_wm_util_list_free (MBWMList * list)
{
- MBWMList * l = list;
-
- while (l)
- {
- MBWMList * f = l;
- l = l->next;
-
- free (f);
- }
+ g_list_free ((GList *)list);
}
diff --git a/matchbox/mb-wm-util.h b/matchbox/mb-wm-util.h
index 817cd74..07b1b86 100644
--- a/matchbox/mb-wm-util.h
+++ b/matchbox/mb-wm-util.h
@@ -78,9 +78,6 @@ mb_wm_util_untrap_x_errors(void);
#define mb_wm_util_list_data(data) (list)->data
MBWMList*
-mb_wm_util_list_alloc_item(void);
-
-MBWMList*
mb_wm_util_list_remove(MBWMList *list, void *data);
int