removed the GListAllocator type and its g_*_allocator_*() function

Tue Nov 24 09:40:00 1998  Tim Janik  <timj@gtk.org>

        * glib.h: removed the GListAllocator type and its g_*_allocator_*()
        function variants (which weren't working anyways) in favour of a
        generic GAllocator type. new functions:
        g_allocator_new, g_allocator_free, g_slist_push_allocator,
        g_slist_pop_allocator, g_list_push_allocator, g_list_pop_allocator,
        g_node_push_allocator and g_node_pop_allocator.

        * gstring.c: removed bogus slist allocator code.
        * gtree.c: maintain own list of free tree nodes and don't waste
        GSLists for that, removed bogus slist allocator code.
        * glist.c: use GAllocators for node allocation.
        * gslist.c: use GAllocators for node allocation.
        * gnode.c: use GAllocators for node allocation.

        * gdataset.c: cleanups wrt automatic initialization.
This commit is contained in:
Tim Janik
1998-11-24 12:18:22 +00:00
committed by Tim Janik
parent eabb208b30
commit 9c1692c260
24 changed files with 924 additions and 516 deletions

140
glist.c
View File

@@ -19,99 +19,104 @@
#include "glib.h"
typedef struct _GRealListAllocator GRealListAllocator;
struct _GRealListAllocator
struct _GAllocator /* from gmem.c */
{
GMemChunk *list_mem_chunk;
GList *free_list;
gchar *name;
guint16 n_preallocs;
guint is_unused : 1;
guint type : 4;
GAllocator *last;
GMemChunk *mem_chunk;
GList *free_lists; /* implementation specific */
};
static GAllocator *current_allocator = NULL;
static GRealListAllocator *default_allocator = NULL;
static GRealListAllocator *current_allocator = NULL;
GListAllocator*
g_list_allocator_new (void)
void
g_list_push_allocator (GAllocator *allocator)
{
GRealListAllocator* allocator = g_new (GRealListAllocator, 1);
allocator->list_mem_chunk = NULL;
allocator->free_list = NULL;
return (GListAllocator*) allocator;
g_return_if_fail (allocator != NULL);
g_return_if_fail (allocator->is_unused == TRUE);
if (allocator->type != G_ALLOCATOR_LIST)
{
allocator->type = G_ALLOCATOR_LIST;
if (allocator->mem_chunk)
{
g_mem_chunk_destroy (allocator->mem_chunk);
allocator->mem_chunk = NULL;
}
}
if (!allocator->mem_chunk)
{
allocator->mem_chunk = g_mem_chunk_new (allocator->name,
sizeof (GList),
sizeof (GList) * allocator->n_preallocs,
G_ALLOC_ONLY);
allocator->free_lists = NULL;
}
allocator->is_unused = FALSE;
allocator->last = current_allocator;
current_allocator = allocator;
}
void
g_list_allocator_free (GListAllocator* fallocator)
g_list_pop_allocator (void)
{
GRealListAllocator* allocator = (GRealListAllocator *) fallocator;
if (allocator && allocator->list_mem_chunk)
g_mem_chunk_destroy (allocator->list_mem_chunk);
if (allocator)
g_free (allocator);
}
GListAllocator*
g_list_set_allocator (GListAllocator* fallocator)
{
GRealListAllocator* allocator = (GRealListAllocator *) fallocator;
GRealListAllocator* old_allocator = current_allocator;
if (allocator)
current_allocator = allocator;
else
if (current_allocator)
{
if (!default_allocator)
default_allocator = (GRealListAllocator*) g_list_allocator_new ();
current_allocator = default_allocator;
}
if (!current_allocator->list_mem_chunk)
current_allocator->list_mem_chunk = g_mem_chunk_new ("list mem chunk",
sizeof (GList),
1024,
G_ALLOC_ONLY);
return (GListAllocator*) (old_allocator == default_allocator ? NULL : old_allocator);
}
GAllocator *allocator;
allocator = current_allocator;
current_allocator = allocator->last;
allocator->last = NULL;
allocator->is_unused = TRUE;
}
}
GList*
g_list_alloc (void)
{
GList *new_list;
g_list_set_allocator (NULL);
if (current_allocator->free_list)
GList *list;
if (!current_allocator)
g_list_push_allocator (g_allocator_new ("GLib default GList allocator", 1024));
if (!current_allocator->free_lists)
{
new_list = current_allocator->free_list;
current_allocator->free_list = current_allocator->free_list->next;
list = g_chunk_new (GList, current_allocator->mem_chunk);
list->data = NULL;
}
else
{
new_list = g_chunk_new (GList, current_allocator->list_mem_chunk);
if (current_allocator->free_lists->data)
{
list = current_allocator->free_lists->data;
current_allocator->free_lists->data = list->next;
list->data = NULL;
}
else
{
list = current_allocator->free_lists;
current_allocator->free_lists = list->next;
}
}
list->next = NULL;
list->prev = NULL;
new_list->data = NULL;
new_list->next = NULL;
new_list->prev = NULL;
return new_list;
return list;
}
void
g_list_free (GList *list)
{
GList *last;
if (list)
{
last = g_list_last (list);
last->next = current_allocator->free_list;
current_allocator->free_list = list;
list->data = list->next;
list->next = current_allocator->free_lists;
current_allocator->free_lists = list;
}
}
@@ -120,8 +125,9 @@ g_list_free_1 (GList *list)
{
if (list)
{
list->next = current_allocator->free_list;
current_allocator->free_list = list;
list->data = NULL;
list->next = current_allocator->free_lists;
current_allocator->free_lists = list;
}
}