-#ifndef DISABLE_MEM_POOLS
-struct _GAllocator /* from gmem.c */
-{
- 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;
-G_LOCK_DEFINE_STATIC (current_allocator);
-
-/* HOLDS: current_allocator_lock */
-static void
-g_list_validate_allocator (GAllocator *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;
-}
-
-void
-g_list_push_allocator(GAllocator *allocator)
-{
- G_LOCK (current_allocator);
- g_list_validate_allocator (allocator);
- allocator->last = current_allocator;
- current_allocator = allocator;
- G_UNLOCK (current_allocator);
-}
-
-void
-g_list_pop_allocator (void)
-{
- G_LOCK (current_allocator);
- if (current_allocator)
- {
- GAllocator *allocator;
-
- allocator = current_allocator;
- current_allocator = allocator->last;
- allocator->last = NULL;
- allocator->is_unused = TRUE;
- }
- G_UNLOCK (current_allocator);
-}
-
-static inline GList*
-_g_list_alloc (void)
-{
- GList *list;
-
- G_LOCK (current_allocator);
- if (!current_allocator)
- {
- GAllocator *allocator = g_allocator_new ("GLib default GList allocator",
- 128);
- g_list_validate_allocator (allocator);
- allocator->last = NULL;
- current_allocator = allocator;
- }
- if (!current_allocator->free_lists)
- {
- list = g_chunk_new (GList, current_allocator->mem_chunk);
- list->data = NULL;
- }
- else
- {
- 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;
- }
- }
- G_UNLOCK (current_allocator);
- list->next = NULL;
- list->prev = NULL;
-
- return list;
-}
-
-GList*
-g_list_alloc (void)
-{
- return _g_list_alloc ();
-}
-
-void
-g_list_free (GList *list)
-{
- if (list)
- {
- GList *last_node = list;
-
-#ifdef ENABLE_GC_FRIENDLY
- while (last_node->next)
- {
- last_node->data = NULL;
- last_node->prev = NULL;
- last_node = last_node->next;
- }
- last_node->data = NULL;
- last_node->prev = NULL;
-#else /* !ENABLE_GC_FRIENDLY */
- list->data = list->next;
-#endif /* ENABLE_GC_FRIENDLY */
-
- G_LOCK (current_allocator);
- last_node->next = current_allocator->free_lists;
- current_allocator->free_lists = list;
- G_UNLOCK (current_allocator);
- }
-}
-
-static inline void
-_g_list_free_1 (GList *list)
-{
- if (list)
- {
- list->data = NULL;