mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-08 18:24:04 +02:00
Patch from Darin Adler to remove GReal* structures in favor of simple
Wed Sep 19 14:05:27 2001 Owen Taylor <otaylor@redhat.com> * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}: Patch from Darin Adler to remove GReal* structures in favor of simple opaque typedefs in cases where there were no non-private members. (#59693)
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
Wed Sep 19 14:05:27 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
|
||||||
|
Patch from Darin Adler to remove GReal* structures in
|
||||||
|
favor of simple opaque typedefs in cases where there
|
||||||
|
were no non-private members. (#59693)
|
||||||
|
|
||||||
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
||||||
|
@@ -1,3 +1,10 @@
|
|||||||
|
Wed Sep 19 14:05:27 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
|
||||||
|
Patch from Darin Adler to remove GReal* structures in
|
||||||
|
favor of simple opaque typedefs in cases where there
|
||||||
|
were no non-private members. (#59693)
|
||||||
|
|
||||||
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
||||||
|
@@ -1,3 +1,10 @@
|
|||||||
|
Wed Sep 19 14:05:27 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
|
||||||
|
Patch from Darin Adler to remove GReal* structures in
|
||||||
|
favor of simple opaque typedefs in cases where there
|
||||||
|
were no non-private members. (#59693)
|
||||||
|
|
||||||
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
||||||
|
@@ -1,3 +1,10 @@
|
|||||||
|
Wed Sep 19 14:05:27 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
|
||||||
|
Patch from Darin Adler to remove GReal* structures in
|
||||||
|
favor of simple opaque typedefs in cases where there
|
||||||
|
were no non-private members. (#59693)
|
||||||
|
|
||||||
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
||||||
|
@@ -1,3 +1,10 @@
|
|||||||
|
Wed Sep 19 14:05:27 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
|
||||||
|
Patch from Darin Adler to remove GReal* structures in
|
||||||
|
favor of simple opaque typedefs in cases where there
|
||||||
|
were no non-private members. (#59693)
|
||||||
|
|
||||||
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
||||||
|
@@ -1,3 +1,10 @@
|
|||||||
|
Wed Sep 19 14:05:27 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
|
||||||
|
Patch from Darin Adler to remove GReal* structures in
|
||||||
|
favor of simple opaque typedefs in cases where there
|
||||||
|
were no non-private members. (#59693)
|
||||||
|
|
||||||
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
||||||
|
@@ -1,3 +1,10 @@
|
|||||||
|
Wed Sep 19 14:05:27 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
|
||||||
|
Patch from Darin Adler to remove GReal* structures in
|
||||||
|
favor of simple opaque typedefs in cases where there
|
||||||
|
were no non-private members. (#59693)
|
||||||
|
|
||||||
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
||||||
|
@@ -1,3 +1,10 @@
|
|||||||
|
Wed Sep 19 14:05:27 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
|
* glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
|
||||||
|
Patch from Darin Adler to remove GReal* structures in
|
||||||
|
favor of simple opaque typedefs in cases where there
|
||||||
|
were no non-private members. (#59693)
|
||||||
|
|
||||||
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
Wed Sep 19 13:03:38 2001 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
* glib/giochannel.c (g_io_channel_read/write_chars): Handle NUL
|
||||||
|
@@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct _GCacheNode GCacheNode;
|
typedef struct _GCacheNode GCacheNode;
|
||||||
typedef struct _GRealCache GRealCache;
|
|
||||||
|
|
||||||
struct _GCacheNode
|
struct _GCacheNode
|
||||||
{
|
{
|
||||||
@@ -41,7 +40,7 @@ struct _GCacheNode
|
|||||||
gint ref_count;
|
gint ref_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GRealCache
|
struct _GCache
|
||||||
{
|
{
|
||||||
/* Called to create a value from a key */
|
/* Called to create a value from a key */
|
||||||
GCacheNewFunc value_new_func;
|
GCacheNewFunc value_new_func;
|
||||||
@@ -79,7 +78,7 @@ g_cache_new (GCacheNewFunc value_new_func,
|
|||||||
GHashFunc hash_value_func,
|
GHashFunc hash_value_func,
|
||||||
GEqualFunc key_equal_func)
|
GEqualFunc key_equal_func)
|
||||||
{
|
{
|
||||||
GRealCache *cache;
|
GCache *cache;
|
||||||
|
|
||||||
g_return_val_if_fail (value_new_func != NULL, NULL);
|
g_return_val_if_fail (value_new_func != NULL, NULL);
|
||||||
g_return_val_if_fail (value_destroy_func != NULL, NULL);
|
g_return_val_if_fail (value_destroy_func != NULL, NULL);
|
||||||
@@ -89,7 +88,7 @@ g_cache_new (GCacheNewFunc value_new_func,
|
|||||||
g_return_val_if_fail (hash_value_func != NULL, NULL);
|
g_return_val_if_fail (hash_value_func != NULL, NULL);
|
||||||
g_return_val_if_fail (key_equal_func != NULL, NULL);
|
g_return_val_if_fail (key_equal_func != NULL, NULL);
|
||||||
|
|
||||||
cache = g_new (GRealCache, 1);
|
cache = g_new (GCache, 1);
|
||||||
cache->value_new_func = value_new_func;
|
cache->value_new_func = value_new_func;
|
||||||
cache->value_destroy_func = value_destroy_func;
|
cache->value_destroy_func = value_destroy_func;
|
||||||
cache->key_dup_func = key_dup_func;
|
cache->key_dup_func = key_dup_func;
|
||||||
@@ -97,47 +96,41 @@ g_cache_new (GCacheNewFunc value_new_func,
|
|||||||
cache->key_table = g_hash_table_new (hash_key_func, key_equal_func);
|
cache->key_table = g_hash_table_new (hash_key_func, key_equal_func);
|
||||||
cache->value_table = g_hash_table_new (hash_value_func, NULL);
|
cache->value_table = g_hash_table_new (hash_value_func, NULL);
|
||||||
|
|
||||||
return (GCache*) cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_cache_destroy (GCache *cache)
|
g_cache_destroy (GCache *cache)
|
||||||
{
|
{
|
||||||
GRealCache *rcache;
|
|
||||||
|
|
||||||
g_return_if_fail (cache != NULL);
|
g_return_if_fail (cache != NULL);
|
||||||
|
|
||||||
rcache = (GRealCache*) cache;
|
g_hash_table_destroy (cache->key_table);
|
||||||
g_hash_table_destroy (rcache->key_table);
|
g_hash_table_destroy (cache->value_table);
|
||||||
g_hash_table_destroy (rcache->value_table);
|
g_free (cache);
|
||||||
g_free (rcache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gpointer
|
gpointer
|
||||||
g_cache_insert (GCache *cache,
|
g_cache_insert (GCache *cache,
|
||||||
gpointer key)
|
gpointer key)
|
||||||
{
|
{
|
||||||
GRealCache *rcache;
|
|
||||||
GCacheNode *node;
|
GCacheNode *node;
|
||||||
gpointer value;
|
gpointer value;
|
||||||
|
|
||||||
g_return_val_if_fail (cache != NULL, NULL);
|
g_return_val_if_fail (cache != NULL, NULL);
|
||||||
|
|
||||||
rcache = (GRealCache*) cache;
|
node = g_hash_table_lookup (cache->key_table, key);
|
||||||
|
|
||||||
node = g_hash_table_lookup (rcache->key_table, key);
|
|
||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
node->ref_count += 1;
|
node->ref_count += 1;
|
||||||
return node->value;
|
return node->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
key = (* rcache->key_dup_func) (key);
|
key = (* cache->key_dup_func) (key);
|
||||||
value = (* rcache->value_new_func) (key);
|
value = (* cache->value_new_func) (key);
|
||||||
node = g_cache_node_new (value);
|
node = g_cache_node_new (value);
|
||||||
|
|
||||||
g_hash_table_insert (rcache->key_table, key, node);
|
g_hash_table_insert (cache->key_table, key, node);
|
||||||
g_hash_table_insert (rcache->value_table, value, key);
|
g_hash_table_insert (cache->value_table, value, key);
|
||||||
|
|
||||||
return node->value;
|
return node->value;
|
||||||
}
|
}
|
||||||
@@ -146,27 +139,24 @@ void
|
|||||||
g_cache_remove (GCache *cache,
|
g_cache_remove (GCache *cache,
|
||||||
gconstpointer value)
|
gconstpointer value)
|
||||||
{
|
{
|
||||||
GRealCache *rcache;
|
|
||||||
GCacheNode *node;
|
GCacheNode *node;
|
||||||
gpointer key;
|
gpointer key;
|
||||||
|
|
||||||
g_return_if_fail (cache != NULL);
|
g_return_if_fail (cache != NULL);
|
||||||
|
|
||||||
rcache = (GRealCache*) cache;
|
key = g_hash_table_lookup (cache->value_table, value);
|
||||||
|
node = g_hash_table_lookup (cache->key_table, key);
|
||||||
key = g_hash_table_lookup (rcache->value_table, value);
|
|
||||||
node = g_hash_table_lookup (rcache->key_table, key);
|
|
||||||
|
|
||||||
g_return_if_fail (node != NULL);
|
g_return_if_fail (node != NULL);
|
||||||
|
|
||||||
node->ref_count -= 1;
|
node->ref_count -= 1;
|
||||||
if (node->ref_count == 0)
|
if (node->ref_count == 0)
|
||||||
{
|
{
|
||||||
g_hash_table_remove (rcache->value_table, value);
|
g_hash_table_remove (cache->value_table, value);
|
||||||
g_hash_table_remove (rcache->key_table, key);
|
g_hash_table_remove (cache->key_table, key);
|
||||||
|
|
||||||
(* rcache->key_destroy_func) (key);
|
(* cache->key_destroy_func) (key);
|
||||||
(* rcache->value_destroy_func) (node->value);
|
(* cache->value_destroy_func) (node->value);
|
||||||
g_cache_node_destroy (node);
|
g_cache_node_destroy (node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,14 +166,10 @@ g_cache_key_foreach (GCache *cache,
|
|||||||
GHFunc func,
|
GHFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GRealCache *rcache;
|
|
||||||
|
|
||||||
g_return_if_fail (cache != NULL);
|
g_return_if_fail (cache != NULL);
|
||||||
g_return_if_fail (func != NULL);
|
g_return_if_fail (func != NULL);
|
||||||
|
|
||||||
rcache = (GRealCache*) cache;
|
g_hash_table_foreach (cache->value_table, func, user_data);
|
||||||
|
|
||||||
g_hash_table_foreach (rcache->value_table, func, user_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -191,14 +177,10 @@ g_cache_value_foreach (GCache *cache,
|
|||||||
GHFunc func,
|
GHFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GRealCache *rcache;
|
|
||||||
|
|
||||||
g_return_if_fail (cache != NULL);
|
g_return_if_fail (cache != NULL);
|
||||||
g_return_if_fail (func != NULL);
|
g_return_if_fail (func != NULL);
|
||||||
|
|
||||||
rcache = (GRealCache*) cache;
|
g_hash_table_foreach (cache->key_table, func, user_data);
|
||||||
|
|
||||||
g_hash_table_foreach (rcache->key_table, func, user_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
206
glib/gmem.c
206
glib/gmem.c
@@ -573,7 +573,6 @@ GMemVTable *glib_mem_profiler_table = &profiler_table;
|
|||||||
/* --- MemChunks --- */
|
/* --- MemChunks --- */
|
||||||
typedef struct _GFreeAtom GFreeAtom;
|
typedef struct _GFreeAtom GFreeAtom;
|
||||||
typedef struct _GMemArea GMemArea;
|
typedef struct _GMemArea GMemArea;
|
||||||
typedef struct _GRealMemChunk GRealMemChunk;
|
|
||||||
|
|
||||||
struct _GFreeAtom
|
struct _GFreeAtom
|
||||||
{
|
{
|
||||||
@@ -597,7 +596,7 @@ struct _GMemArea
|
|||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GRealMemChunk
|
struct _GMemChunk
|
||||||
{
|
{
|
||||||
const gchar *name; /* name of this MemChunk...used for debugging output */
|
const gchar *name; /* name of this MemChunk...used for debugging output */
|
||||||
gint type; /* the type of MemChunk: ALLOC_ONLY or ALLOC_AND_FREE */
|
gint type; /* the type of MemChunk: ALLOC_ONLY or ALLOC_AND_FREE */
|
||||||
@@ -610,8 +609,8 @@ struct _GRealMemChunk
|
|||||||
GMemArea *free_mem_area; /* the free area...which is about to be destroyed */
|
GMemArea *free_mem_area; /* the free area...which is about to be destroyed */
|
||||||
GFreeAtom *free_atoms; /* the free atoms list */
|
GFreeAtom *free_atoms; /* the free atoms list */
|
||||||
GTree *mem_tree; /* tree of mem areas sorted by memory address */
|
GTree *mem_tree; /* tree of mem areas sorted by memory address */
|
||||||
GRealMemChunk *next; /* pointer to the next chunk */
|
GMemChunk *next; /* pointer to the next chunk */
|
||||||
GRealMemChunk *prev; /* pointer to the previous chunk */
|
GMemChunk *prev; /* pointer to the previous chunk */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -627,7 +626,7 @@ static gint g_mem_chunk_area_search (GMemArea *a,
|
|||||||
* g_malloc, the same holds true for StaticPrivate
|
* g_malloc, the same holds true for StaticPrivate
|
||||||
*/
|
*/
|
||||||
static GMutex *mem_chunks_lock = NULL;
|
static GMutex *mem_chunks_lock = NULL;
|
||||||
static GRealMemChunk *mem_chunks = NULL;
|
static GMemChunk *mem_chunks = NULL;
|
||||||
|
|
||||||
GMemChunk*
|
GMemChunk*
|
||||||
g_mem_chunk_new (const gchar *name,
|
g_mem_chunk_new (const gchar *name,
|
||||||
@@ -635,7 +634,7 @@ g_mem_chunk_new (const gchar *name,
|
|||||||
gulong area_size,
|
gulong area_size,
|
||||||
gint type)
|
gint type)
|
||||||
{
|
{
|
||||||
GRealMemChunk *mem_chunk;
|
GMemChunk *mem_chunk;
|
||||||
gulong rarea_size;
|
gulong rarea_size;
|
||||||
|
|
||||||
g_return_val_if_fail (atom_size > 0, NULL);
|
g_return_val_if_fail (atom_size > 0, NULL);
|
||||||
@@ -646,7 +645,7 @@ g_mem_chunk_new (const gchar *name,
|
|||||||
area_size = (area_size + atom_size - 1) / atom_size;
|
area_size = (area_size + atom_size - 1) / atom_size;
|
||||||
area_size *= atom_size;
|
area_size *= atom_size;
|
||||||
|
|
||||||
mem_chunk = g_new (struct _GRealMemChunk, 1);
|
mem_chunk = g_new (GMemChunk, 1);
|
||||||
mem_chunk->name = name;
|
mem_chunk->name = name;
|
||||||
mem_chunk->type = type;
|
mem_chunk->type = type;
|
||||||
mem_chunk->num_mem_areas = 0;
|
mem_chunk->num_mem_areas = 0;
|
||||||
@@ -678,13 +677,12 @@ g_mem_chunk_new (const gchar *name,
|
|||||||
|
|
||||||
LEAVE_MEM_CHUNK_ROUTINE ();
|
LEAVE_MEM_CHUNK_ROUTINE ();
|
||||||
|
|
||||||
return ((GMemChunk*) mem_chunk);
|
return mem_chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_mem_chunk_destroy (GMemChunk *mem_chunk)
|
g_mem_chunk_destroy (GMemChunk *mem_chunk)
|
||||||
{
|
{
|
||||||
GRealMemChunk *rmem_chunk;
|
|
||||||
GMemArea *mem_areas;
|
GMemArea *mem_areas;
|
||||||
GMemArea *temp_area;
|
GMemArea *temp_area;
|
||||||
|
|
||||||
@@ -692,9 +690,7 @@ g_mem_chunk_destroy (GMemChunk *mem_chunk)
|
|||||||
|
|
||||||
ENTER_MEM_CHUNK_ROUTINE ();
|
ENTER_MEM_CHUNK_ROUTINE ();
|
||||||
|
|
||||||
rmem_chunk = (GRealMemChunk*) mem_chunk;
|
mem_areas = mem_chunk->mem_areas;
|
||||||
|
|
||||||
mem_areas = rmem_chunk->mem_areas;
|
|
||||||
while (mem_areas)
|
while (mem_areas)
|
||||||
{
|
{
|
||||||
temp_area = mem_areas;
|
temp_area = mem_areas;
|
||||||
@@ -702,20 +698,20 @@ g_mem_chunk_destroy (GMemChunk *mem_chunk)
|
|||||||
g_free (temp_area);
|
g_free (temp_area);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rmem_chunk->next)
|
if (mem_chunk->next)
|
||||||
rmem_chunk->next->prev = rmem_chunk->prev;
|
mem_chunk->next->prev = mem_chunk->prev;
|
||||||
if (rmem_chunk->prev)
|
if (mem_chunk->prev)
|
||||||
rmem_chunk->prev->next = rmem_chunk->next;
|
mem_chunk->prev->next = mem_chunk->next;
|
||||||
|
|
||||||
g_mutex_lock (mem_chunks_lock);
|
g_mutex_lock (mem_chunks_lock);
|
||||||
if (rmem_chunk == mem_chunks)
|
if (mem_chunk == mem_chunks)
|
||||||
mem_chunks = mem_chunks->next;
|
mem_chunks = mem_chunks->next;
|
||||||
g_mutex_unlock (mem_chunks_lock);
|
g_mutex_unlock (mem_chunks_lock);
|
||||||
|
|
||||||
if (rmem_chunk->type == G_ALLOC_AND_FREE)
|
if (mem_chunk->type == G_ALLOC_AND_FREE)
|
||||||
g_tree_destroy (rmem_chunk->mem_tree);
|
g_tree_destroy (mem_chunk->mem_tree);
|
||||||
|
|
||||||
g_free (rmem_chunk);
|
g_free (mem_chunk);
|
||||||
|
|
||||||
LEAVE_MEM_CHUNK_ROUTINE ();
|
LEAVE_MEM_CHUNK_ROUTINE ();
|
||||||
}
|
}
|
||||||
@@ -723,7 +719,6 @@ g_mem_chunk_destroy (GMemChunk *mem_chunk)
|
|||||||
gpointer
|
gpointer
|
||||||
g_mem_chunk_alloc (GMemChunk *mem_chunk)
|
g_mem_chunk_alloc (GMemChunk *mem_chunk)
|
||||||
{
|
{
|
||||||
GRealMemChunk *rmem_chunk;
|
|
||||||
GMemArea *temp_area;
|
GMemArea *temp_area;
|
||||||
gpointer mem;
|
gpointer mem;
|
||||||
|
|
||||||
@@ -731,20 +726,18 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
|
|||||||
|
|
||||||
g_return_val_if_fail (mem_chunk != NULL, NULL);
|
g_return_val_if_fail (mem_chunk != NULL, NULL);
|
||||||
|
|
||||||
rmem_chunk = (GRealMemChunk*) mem_chunk;
|
while (mem_chunk->free_atoms)
|
||||||
|
|
||||||
while (rmem_chunk->free_atoms)
|
|
||||||
{
|
{
|
||||||
/* Get the first piece of memory on the "free_atoms" list.
|
/* Get the first piece of memory on the "free_atoms" list.
|
||||||
* We can go ahead and destroy the list node we used to keep
|
* We can go ahead and destroy the list node we used to keep
|
||||||
* track of it with and to update the "free_atoms" list to
|
* track of it with and to update the "free_atoms" list to
|
||||||
* point to its next element.
|
* point to its next element.
|
||||||
*/
|
*/
|
||||||
mem = rmem_chunk->free_atoms;
|
mem = mem_chunk->free_atoms;
|
||||||
rmem_chunk->free_atoms = rmem_chunk->free_atoms->next;
|
mem_chunk->free_atoms = mem_chunk->free_atoms->next;
|
||||||
|
|
||||||
/* Determine which area this piece of memory is allocated from */
|
/* Determine which area this piece of memory is allocated from */
|
||||||
temp_area = g_tree_search (rmem_chunk->mem_tree,
|
temp_area = g_tree_search (mem_chunk->mem_tree,
|
||||||
(GCompareFunc) g_mem_chunk_area_search,
|
(GCompareFunc) g_mem_chunk_area_search,
|
||||||
mem);
|
mem);
|
||||||
|
|
||||||
@@ -763,32 +756,32 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
|
|||||||
if (temp_area->mark)
|
if (temp_area->mark)
|
||||||
{
|
{
|
||||||
/* Update the "free" memory available in that area */
|
/* Update the "free" memory available in that area */
|
||||||
temp_area->free += rmem_chunk->atom_size;
|
temp_area->free += mem_chunk->atom_size;
|
||||||
|
|
||||||
if (temp_area->free == rmem_chunk->area_size)
|
if (temp_area->free == mem_chunk->area_size)
|
||||||
{
|
{
|
||||||
if (temp_area == rmem_chunk->mem_area)
|
if (temp_area == mem_chunk->mem_area)
|
||||||
rmem_chunk->mem_area = NULL;
|
mem_chunk->mem_area = NULL;
|
||||||
|
|
||||||
if (rmem_chunk->free_mem_area)
|
if (mem_chunk->free_mem_area)
|
||||||
{
|
{
|
||||||
rmem_chunk->num_mem_areas -= 1;
|
mem_chunk->num_mem_areas -= 1;
|
||||||
|
|
||||||
if (temp_area->next)
|
if (temp_area->next)
|
||||||
temp_area->next->prev = temp_area->prev;
|
temp_area->next->prev = temp_area->prev;
|
||||||
if (temp_area->prev)
|
if (temp_area->prev)
|
||||||
temp_area->prev->next = temp_area->next;
|
temp_area->prev->next = temp_area->next;
|
||||||
if (temp_area == rmem_chunk->mem_areas)
|
if (temp_area == mem_chunk->mem_areas)
|
||||||
rmem_chunk->mem_areas = rmem_chunk->mem_areas->next;
|
mem_chunk->mem_areas = mem_chunk->mem_areas->next;
|
||||||
|
|
||||||
if (rmem_chunk->type == G_ALLOC_AND_FREE)
|
if (mem_chunk->type == G_ALLOC_AND_FREE)
|
||||||
g_tree_remove (rmem_chunk->mem_tree, temp_area);
|
g_tree_remove (mem_chunk->mem_tree, temp_area);
|
||||||
g_free (temp_area);
|
g_free (temp_area);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rmem_chunk->free_mem_area = temp_area;
|
mem_chunk->free_mem_area = temp_area;
|
||||||
|
|
||||||
rmem_chunk->num_marked_areas -= 1;
|
mem_chunk->num_marked_areas -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -807,50 +800,50 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
|
|||||||
* then allocate a new mem area. We'll first check and see if we can use
|
* then allocate a new mem area. We'll first check and see if we can use
|
||||||
* the "free_mem_area". Otherwise we'll just malloc the mem area.
|
* the "free_mem_area". Otherwise we'll just malloc the mem area.
|
||||||
*/
|
*/
|
||||||
if ((!rmem_chunk->mem_area) ||
|
if ((!mem_chunk->mem_area) ||
|
||||||
((rmem_chunk->mem_area->index + rmem_chunk->atom_size) > rmem_chunk->area_size))
|
((mem_chunk->mem_area->index + mem_chunk->atom_size) > mem_chunk->area_size))
|
||||||
{
|
{
|
||||||
if (rmem_chunk->free_mem_area)
|
if (mem_chunk->free_mem_area)
|
||||||
{
|
{
|
||||||
rmem_chunk->mem_area = rmem_chunk->free_mem_area;
|
mem_chunk->mem_area = mem_chunk->free_mem_area;
|
||||||
rmem_chunk->free_mem_area = NULL;
|
mem_chunk->free_mem_area = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_GC_FRIENDLY
|
#ifdef ENABLE_GC_FRIENDLY
|
||||||
rmem_chunk->mem_area = (GMemArea*) g_malloc0 (sizeof (GMemArea) -
|
mem_chunk->mem_area = (GMemArea*) g_malloc0 (sizeof (GMemArea) -
|
||||||
MEM_AREA_SIZE +
|
|
||||||
rmem_chunk->area_size);
|
|
||||||
#else /* !ENABLE_GC_FRIENDLY */
|
|
||||||
rmem_chunk->mem_area = (GMemArea*) g_malloc (sizeof (GMemArea) -
|
|
||||||
MEM_AREA_SIZE +
|
MEM_AREA_SIZE +
|
||||||
rmem_chunk->area_size);
|
mem_chunk->area_size);
|
||||||
|
#else /* !ENABLE_GC_FRIENDLY */
|
||||||
|
mem_chunk->mem_area = (GMemArea*) g_malloc (sizeof (GMemArea) -
|
||||||
|
MEM_AREA_SIZE +
|
||||||
|
mem_chunk->area_size);
|
||||||
#endif /* ENABLE_GC_FRIENDLY */
|
#endif /* ENABLE_GC_FRIENDLY */
|
||||||
|
|
||||||
rmem_chunk->num_mem_areas += 1;
|
mem_chunk->num_mem_areas += 1;
|
||||||
rmem_chunk->mem_area->next = rmem_chunk->mem_areas;
|
mem_chunk->mem_area->next = mem_chunk->mem_areas;
|
||||||
rmem_chunk->mem_area->prev = NULL;
|
mem_chunk->mem_area->prev = NULL;
|
||||||
|
|
||||||
if (rmem_chunk->mem_areas)
|
if (mem_chunk->mem_areas)
|
||||||
rmem_chunk->mem_areas->prev = rmem_chunk->mem_area;
|
mem_chunk->mem_areas->prev = mem_chunk->mem_area;
|
||||||
rmem_chunk->mem_areas = rmem_chunk->mem_area;
|
mem_chunk->mem_areas = mem_chunk->mem_area;
|
||||||
|
|
||||||
if (rmem_chunk->type == G_ALLOC_AND_FREE)
|
if (mem_chunk->type == G_ALLOC_AND_FREE)
|
||||||
g_tree_insert (rmem_chunk->mem_tree, rmem_chunk->mem_area, rmem_chunk->mem_area);
|
g_tree_insert (mem_chunk->mem_tree, mem_chunk->mem_area, mem_chunk->mem_area);
|
||||||
}
|
}
|
||||||
|
|
||||||
rmem_chunk->mem_area->index = 0;
|
mem_chunk->mem_area->index = 0;
|
||||||
rmem_chunk->mem_area->free = rmem_chunk->area_size;
|
mem_chunk->mem_area->free = mem_chunk->area_size;
|
||||||
rmem_chunk->mem_area->allocated = 0;
|
mem_chunk->mem_area->allocated = 0;
|
||||||
rmem_chunk->mem_area->mark = 0;
|
mem_chunk->mem_area->mark = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the memory and modify the state variables appropriately.
|
/* Get the memory and modify the state variables appropriately.
|
||||||
*/
|
*/
|
||||||
mem = (gpointer) &rmem_chunk->mem_area->mem[rmem_chunk->mem_area->index];
|
mem = (gpointer) &mem_chunk->mem_area->mem[mem_chunk->mem_area->index];
|
||||||
rmem_chunk->mem_area->index += rmem_chunk->atom_size;
|
mem_chunk->mem_area->index += mem_chunk->atom_size;
|
||||||
rmem_chunk->mem_area->free -= rmem_chunk->atom_size;
|
mem_chunk->mem_area->free -= mem_chunk->atom_size;
|
||||||
rmem_chunk->mem_area->allocated += 1;
|
mem_chunk->mem_area->allocated += 1;
|
||||||
|
|
||||||
outa_here:
|
outa_here:
|
||||||
|
|
||||||
@@ -867,9 +860,7 @@ g_mem_chunk_alloc0 (GMemChunk *mem_chunk)
|
|||||||
mem = g_mem_chunk_alloc (mem_chunk);
|
mem = g_mem_chunk_alloc (mem_chunk);
|
||||||
if (mem)
|
if (mem)
|
||||||
{
|
{
|
||||||
GRealMemChunk *rmem_chunk = (GRealMemChunk*) mem_chunk;
|
memset (mem, 0, mem_chunk->atom_size);
|
||||||
|
|
||||||
memset (mem, 0, rmem_chunk->atom_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
@@ -879,7 +870,6 @@ void
|
|||||||
g_mem_chunk_free (GMemChunk *mem_chunk,
|
g_mem_chunk_free (GMemChunk *mem_chunk,
|
||||||
gpointer mem)
|
gpointer mem)
|
||||||
{
|
{
|
||||||
GRealMemChunk *rmem_chunk;
|
|
||||||
GMemArea *temp_area;
|
GMemArea *temp_area;
|
||||||
GFreeAtom *free_atom;
|
GFreeAtom *free_atom;
|
||||||
|
|
||||||
@@ -888,23 +878,21 @@ g_mem_chunk_free (GMemChunk *mem_chunk,
|
|||||||
|
|
||||||
ENTER_MEM_CHUNK_ROUTINE ();
|
ENTER_MEM_CHUNK_ROUTINE ();
|
||||||
|
|
||||||
rmem_chunk = (GRealMemChunk*) mem_chunk;
|
|
||||||
|
|
||||||
#ifdef ENABLE_GC_FRIENDLY
|
#ifdef ENABLE_GC_FRIENDLY
|
||||||
memset (mem, 0, rmem_chunk->atom_size);
|
memset (mem, 0, mem_chunk->atom_size);
|
||||||
#endif /* ENABLE_GC_FRIENDLY */
|
#endif /* ENABLE_GC_FRIENDLY */
|
||||||
|
|
||||||
/* Don't do anything if this is an ALLOC_ONLY chunk
|
/* Don't do anything if this is an ALLOC_ONLY chunk
|
||||||
*/
|
*/
|
||||||
if (rmem_chunk->type == G_ALLOC_AND_FREE)
|
if (mem_chunk->type == G_ALLOC_AND_FREE)
|
||||||
{
|
{
|
||||||
/* Place the memory on the "free_atoms" list
|
/* Place the memory on the "free_atoms" list
|
||||||
*/
|
*/
|
||||||
free_atom = (GFreeAtom*) mem;
|
free_atom = (GFreeAtom*) mem;
|
||||||
free_atom->next = rmem_chunk->free_atoms;
|
free_atom->next = mem_chunk->free_atoms;
|
||||||
rmem_chunk->free_atoms = free_atom;
|
mem_chunk->free_atoms = free_atom;
|
||||||
|
|
||||||
temp_area = g_tree_search (rmem_chunk->mem_tree,
|
temp_area = g_tree_search (mem_chunk->mem_tree,
|
||||||
(GCompareFunc) g_mem_chunk_area_search,
|
(GCompareFunc) g_mem_chunk_area_search,
|
||||||
mem);
|
mem);
|
||||||
|
|
||||||
@@ -913,7 +901,7 @@ g_mem_chunk_free (GMemChunk *mem_chunk,
|
|||||||
if (temp_area->allocated == 0)
|
if (temp_area->allocated == 0)
|
||||||
{
|
{
|
||||||
temp_area->mark = 1;
|
temp_area->mark = 1;
|
||||||
rmem_chunk->num_marked_areas += 1;
|
mem_chunk->num_marked_areas += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -924,7 +912,6 @@ g_mem_chunk_free (GMemChunk *mem_chunk,
|
|||||||
void
|
void
|
||||||
g_mem_chunk_clean (GMemChunk *mem_chunk)
|
g_mem_chunk_clean (GMemChunk *mem_chunk)
|
||||||
{
|
{
|
||||||
GRealMemChunk *rmem_chunk;
|
|
||||||
GMemArea *mem_area;
|
GMemArea *mem_area;
|
||||||
GFreeAtom *prev_free_atom;
|
GFreeAtom *prev_free_atom;
|
||||||
GFreeAtom *temp_free_atom;
|
GFreeAtom *temp_free_atom;
|
||||||
@@ -934,18 +921,16 @@ g_mem_chunk_clean (GMemChunk *mem_chunk)
|
|||||||
|
|
||||||
ENTER_MEM_CHUNK_ROUTINE ();
|
ENTER_MEM_CHUNK_ROUTINE ();
|
||||||
|
|
||||||
rmem_chunk = (GRealMemChunk*) mem_chunk;
|
if (mem_chunk->type == G_ALLOC_AND_FREE)
|
||||||
|
|
||||||
if (rmem_chunk->type == G_ALLOC_AND_FREE)
|
|
||||||
{
|
{
|
||||||
prev_free_atom = NULL;
|
prev_free_atom = NULL;
|
||||||
temp_free_atom = rmem_chunk->free_atoms;
|
temp_free_atom = mem_chunk->free_atoms;
|
||||||
|
|
||||||
while (temp_free_atom)
|
while (temp_free_atom)
|
||||||
{
|
{
|
||||||
mem = (gpointer) temp_free_atom;
|
mem = (gpointer) temp_free_atom;
|
||||||
|
|
||||||
mem_area = g_tree_search (rmem_chunk->mem_tree,
|
mem_area = g_tree_search (mem_chunk->mem_tree,
|
||||||
(GCompareFunc) g_mem_chunk_area_search,
|
(GCompareFunc) g_mem_chunk_area_search,
|
||||||
mem);
|
mem);
|
||||||
|
|
||||||
@@ -957,26 +942,26 @@ g_mem_chunk_clean (GMemChunk *mem_chunk)
|
|||||||
if (prev_free_atom)
|
if (prev_free_atom)
|
||||||
prev_free_atom->next = temp_free_atom->next;
|
prev_free_atom->next = temp_free_atom->next;
|
||||||
else
|
else
|
||||||
rmem_chunk->free_atoms = temp_free_atom->next;
|
mem_chunk->free_atoms = temp_free_atom->next;
|
||||||
temp_free_atom = temp_free_atom->next;
|
temp_free_atom = temp_free_atom->next;
|
||||||
|
|
||||||
mem_area->free += rmem_chunk->atom_size;
|
mem_area->free += mem_chunk->atom_size;
|
||||||
if (mem_area->free == rmem_chunk->area_size)
|
if (mem_area->free == mem_chunk->area_size)
|
||||||
{
|
{
|
||||||
rmem_chunk->num_mem_areas -= 1;
|
mem_chunk->num_mem_areas -= 1;
|
||||||
rmem_chunk->num_marked_areas -= 1;
|
mem_chunk->num_marked_areas -= 1;
|
||||||
|
|
||||||
if (mem_area->next)
|
if (mem_area->next)
|
||||||
mem_area->next->prev = mem_area->prev;
|
mem_area->next->prev = mem_area->prev;
|
||||||
if (mem_area->prev)
|
if (mem_area->prev)
|
||||||
mem_area->prev->next = mem_area->next;
|
mem_area->prev->next = mem_area->next;
|
||||||
if (mem_area == rmem_chunk->mem_areas)
|
if (mem_area == mem_chunk->mem_areas)
|
||||||
rmem_chunk->mem_areas = rmem_chunk->mem_areas->next;
|
mem_chunk->mem_areas = mem_chunk->mem_areas->next;
|
||||||
if (mem_area == rmem_chunk->mem_area)
|
if (mem_area == mem_chunk->mem_area)
|
||||||
rmem_chunk->mem_area = NULL;
|
mem_chunk->mem_area = NULL;
|
||||||
|
|
||||||
if (rmem_chunk->type == G_ALLOC_AND_FREE)
|
if (mem_chunk->type == G_ALLOC_AND_FREE)
|
||||||
g_tree_remove (rmem_chunk->mem_tree, mem_area);
|
g_tree_remove (mem_chunk->mem_tree, mem_area);
|
||||||
g_free (mem_area);
|
g_free (mem_area);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -993,7 +978,6 @@ g_mem_chunk_clean (GMemChunk *mem_chunk)
|
|||||||
void
|
void
|
||||||
g_mem_chunk_reset (GMemChunk *mem_chunk)
|
g_mem_chunk_reset (GMemChunk *mem_chunk)
|
||||||
{
|
{
|
||||||
GRealMemChunk *rmem_chunk;
|
|
||||||
GMemArea *mem_areas;
|
GMemArea *mem_areas;
|
||||||
GMemArea *temp_area;
|
GMemArea *temp_area;
|
||||||
|
|
||||||
@@ -1001,12 +985,10 @@ g_mem_chunk_reset (GMemChunk *mem_chunk)
|
|||||||
|
|
||||||
ENTER_MEM_CHUNK_ROUTINE ();
|
ENTER_MEM_CHUNK_ROUTINE ();
|
||||||
|
|
||||||
rmem_chunk = (GRealMemChunk*) mem_chunk;
|
mem_areas = mem_chunk->mem_areas;
|
||||||
|
mem_chunk->num_mem_areas = 0;
|
||||||
mem_areas = rmem_chunk->mem_areas;
|
mem_chunk->mem_areas = NULL;
|
||||||
rmem_chunk->num_mem_areas = 0;
|
mem_chunk->mem_area = NULL;
|
||||||
rmem_chunk->mem_areas = NULL;
|
|
||||||
rmem_chunk->mem_area = NULL;
|
|
||||||
|
|
||||||
while (mem_areas)
|
while (mem_areas)
|
||||||
{
|
{
|
||||||
@@ -1015,11 +997,11 @@ g_mem_chunk_reset (GMemChunk *mem_chunk)
|
|||||||
g_free (temp_area);
|
g_free (temp_area);
|
||||||
}
|
}
|
||||||
|
|
||||||
rmem_chunk->free_atoms = NULL;
|
mem_chunk->free_atoms = NULL;
|
||||||
|
|
||||||
if (rmem_chunk->mem_tree)
|
if (mem_chunk->mem_tree)
|
||||||
g_tree_destroy (rmem_chunk->mem_tree);
|
g_tree_destroy (mem_chunk->mem_tree);
|
||||||
rmem_chunk->mem_tree = g_tree_new ((GCompareFunc) g_mem_chunk_area_compare);
|
mem_chunk->mem_tree = g_tree_new ((GCompareFunc) g_mem_chunk_area_compare);
|
||||||
|
|
||||||
LEAVE_MEM_CHUNK_ROUTINE ();
|
LEAVE_MEM_CHUNK_ROUTINE ();
|
||||||
}
|
}
|
||||||
@@ -1027,31 +1009,29 @@ g_mem_chunk_reset (GMemChunk *mem_chunk)
|
|||||||
void
|
void
|
||||||
g_mem_chunk_print (GMemChunk *mem_chunk)
|
g_mem_chunk_print (GMemChunk *mem_chunk)
|
||||||
{
|
{
|
||||||
GRealMemChunk *rmem_chunk;
|
|
||||||
GMemArea *mem_areas;
|
GMemArea *mem_areas;
|
||||||
gulong mem;
|
gulong mem;
|
||||||
|
|
||||||
g_return_if_fail (mem_chunk != NULL);
|
g_return_if_fail (mem_chunk != NULL);
|
||||||
|
|
||||||
rmem_chunk = (GRealMemChunk*) mem_chunk;
|
mem_areas = mem_chunk->mem_areas;
|
||||||
mem_areas = rmem_chunk->mem_areas;
|
|
||||||
mem = 0;
|
mem = 0;
|
||||||
|
|
||||||
while (mem_areas)
|
while (mem_areas)
|
||||||
{
|
{
|
||||||
mem += rmem_chunk->area_size - mem_areas->free;
|
mem += mem_chunk->area_size - mem_areas->free;
|
||||||
mem_areas = mem_areas->next;
|
mem_areas = mem_areas->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
|
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
|
||||||
"%s: %ld bytes using %d mem areas",
|
"%s: %ld bytes using %d mem areas",
|
||||||
rmem_chunk->name, mem, rmem_chunk->num_mem_areas);
|
mem_chunk->name, mem, mem_chunk->num_mem_areas);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_mem_chunk_info (void)
|
g_mem_chunk_info (void)
|
||||||
{
|
{
|
||||||
GRealMemChunk *mem_chunk;
|
GMemChunk *mem_chunk;
|
||||||
gint count;
|
gint count;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
@@ -1080,7 +1060,7 @@ g_mem_chunk_info (void)
|
|||||||
void
|
void
|
||||||
g_blow_chunks (void)
|
g_blow_chunks (void)
|
||||||
{
|
{
|
||||||
GRealMemChunk *mem_chunk;
|
GMemChunk *mem_chunk;
|
||||||
|
|
||||||
g_mutex_lock (mem_chunks_lock);
|
g_mutex_lock (mem_chunks_lock);
|
||||||
mem_chunk = mem_chunks;
|
mem_chunk = mem_chunks;
|
||||||
|
98
glib/grel.c
98
glib/grel.c
@@ -31,10 +31,9 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef struct _GRealRelation GRealRelation;
|
|
||||||
typedef struct _GRealTuples GRealTuples;
|
typedef struct _GRealTuples GRealTuples;
|
||||||
|
|
||||||
struct _GRealRelation
|
struct _GRelation
|
||||||
{
|
{
|
||||||
gint fields;
|
gint fields;
|
||||||
gint current_field;
|
gint current_field;
|
||||||
@@ -102,7 +101,7 @@ tuple_equal (gint fields)
|
|||||||
GRelation*
|
GRelation*
|
||||||
g_relation_new (gint fields)
|
g_relation_new (gint fields)
|
||||||
{
|
{
|
||||||
GRealRelation* rel = g_new0 (GRealRelation, 1);
|
GRelation* rel = g_new0 (GRelation, 1);
|
||||||
|
|
||||||
rel->fields = fields;
|
rel->fields = fields;
|
||||||
rel->tuple_chunk = g_mem_chunk_new ("Relation Chunk",
|
rel->tuple_chunk = g_mem_chunk_new ("Relation Chunk",
|
||||||
@@ -112,7 +111,7 @@ g_relation_new (gint fields)
|
|||||||
rel->all_tuples = g_hash_table_new (tuple_hash (fields), tuple_equal (fields));
|
rel->all_tuples = g_hash_table_new (tuple_hash (fields), tuple_equal (fields));
|
||||||
rel->hashed_tuple_tables = g_new0 (GHashTable*, fields);
|
rel->hashed_tuple_tables = g_new0 (GHashTable*, fields);
|
||||||
|
|
||||||
return (GRelation*) rel;
|
return rel;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -124,25 +123,24 @@ g_relation_free_array (gpointer key, gpointer value, gpointer user_data)
|
|||||||
void
|
void
|
||||||
g_relation_destroy (GRelation *relation)
|
g_relation_destroy (GRelation *relation)
|
||||||
{
|
{
|
||||||
GRealRelation *rel = (GRealRelation *) relation;
|
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
if (rel)
|
if (relation)
|
||||||
{
|
{
|
||||||
g_hash_table_destroy (rel->all_tuples);
|
g_hash_table_destroy (relation->all_tuples);
|
||||||
g_mem_chunk_destroy (rel->tuple_chunk);
|
g_mem_chunk_destroy (relation->tuple_chunk);
|
||||||
|
|
||||||
for (i = 0; i < rel->fields; i += 1)
|
for (i = 0; i < relation->fields; i += 1)
|
||||||
{
|
{
|
||||||
if (rel->hashed_tuple_tables[i])
|
if (relation->hashed_tuple_tables[i])
|
||||||
{
|
{
|
||||||
g_hash_table_foreach (rel->hashed_tuple_tables[i], g_relation_free_array, NULL);
|
g_hash_table_foreach (relation->hashed_tuple_tables[i], g_relation_free_array, NULL);
|
||||||
g_hash_table_destroy (rel->hashed_tuple_tables[i]);
|
g_hash_table_destroy (relation->hashed_tuple_tables[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (rel->hashed_tuple_tables);
|
g_free (relation->hashed_tuple_tables);
|
||||||
g_free (rel);
|
g_free (relation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,42 +150,39 @@ g_relation_index (GRelation *relation,
|
|||||||
GHashFunc hash_func,
|
GHashFunc hash_func,
|
||||||
GEqualFunc key_equal_func)
|
GEqualFunc key_equal_func)
|
||||||
{
|
{
|
||||||
GRealRelation *rel = (GRealRelation *) relation;
|
|
||||||
|
|
||||||
g_return_if_fail (relation != NULL);
|
g_return_if_fail (relation != NULL);
|
||||||
|
|
||||||
g_return_if_fail (rel->count == 0 && rel->hashed_tuple_tables[field] == NULL);
|
g_return_if_fail (relation->count == 0 && relation->hashed_tuple_tables[field] == NULL);
|
||||||
|
|
||||||
rel->hashed_tuple_tables[field] = g_hash_table_new (hash_func, key_equal_func);
|
relation->hashed_tuple_tables[field] = g_hash_table_new (hash_func, key_equal_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_relation_insert (GRelation *relation,
|
g_relation_insert (GRelation *relation,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
GRealRelation *rel = (GRealRelation *) relation;
|
gpointer* tuple = g_chunk_new (gpointer, relation->tuple_chunk);
|
||||||
gpointer* tuple = g_chunk_new (gpointer, rel->tuple_chunk);
|
|
||||||
va_list args;
|
va_list args;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
va_start(args, relation);
|
va_start(args, relation);
|
||||||
|
|
||||||
for (i = 0; i < rel->fields; i += 1)
|
for (i = 0; i < relation->fields; i += 1)
|
||||||
tuple[i] = va_arg(args, gpointer);
|
tuple[i] = va_arg(args, gpointer);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
g_hash_table_insert (rel->all_tuples, tuple, tuple);
|
g_hash_table_insert (relation->all_tuples, tuple, tuple);
|
||||||
|
|
||||||
rel->count += 1;
|
relation->count += 1;
|
||||||
|
|
||||||
for (i = 0; i < rel->fields; i += 1)
|
for (i = 0; i < relation->fields; i += 1)
|
||||||
{
|
{
|
||||||
GHashTable *table;
|
GHashTable *table;
|
||||||
gpointer key;
|
gpointer key;
|
||||||
GHashTable *per_key_table;
|
GHashTable *per_key_table;
|
||||||
|
|
||||||
table = rel->hashed_tuple_tables[i];
|
table = relation->hashed_tuple_tables[i];
|
||||||
|
|
||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
continue;
|
continue;
|
||||||
@@ -197,7 +192,7 @@ g_relation_insert (GRelation *relation,
|
|||||||
|
|
||||||
if (per_key_table == NULL)
|
if (per_key_table == NULL)
|
||||||
{
|
{
|
||||||
per_key_table = g_hash_table_new (tuple_hash (rel->fields), tuple_equal (rel->fields));
|
per_key_table = g_hash_table_new (tuple_hash (relation->fields), tuple_equal (relation->fields));
|
||||||
g_hash_table_insert (table, key, per_key_table);
|
g_hash_table_insert (table, key, per_key_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +206,7 @@ g_relation_delete_tuple (gpointer tuple_key,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
gpointer *tuple = (gpointer*) tuple_value;
|
gpointer *tuple = (gpointer*) tuple_value;
|
||||||
GRealRelation *rel = (GRealRelation *) user_data;
|
GRelation *rel = (GRelation *) user_data;
|
||||||
gint j;
|
gint j;
|
||||||
|
|
||||||
g_assert (tuple_key == tuple_value);
|
g_assert (tuple_key == tuple_value);
|
||||||
@@ -246,10 +241,9 @@ g_relation_delete (GRelation *relation,
|
|||||||
gconstpointer key,
|
gconstpointer key,
|
||||||
gint field)
|
gint field)
|
||||||
{
|
{
|
||||||
GRealRelation *rel = (GRealRelation *) relation;
|
GHashTable *table = relation->hashed_tuple_tables[field];
|
||||||
GHashTable *table = rel->hashed_tuple_tables[field];
|
|
||||||
GHashTable *key_table;
|
GHashTable *key_table;
|
||||||
gint count = rel->count;
|
gint count = relation->count;
|
||||||
|
|
||||||
g_return_val_if_fail (relation != NULL, 0);
|
g_return_val_if_fail (relation != NULL, 0);
|
||||||
g_return_val_if_fail (table != NULL, 0);
|
g_return_val_if_fail (table != NULL, 0);
|
||||||
@@ -259,9 +253,9 @@ g_relation_delete (GRelation *relation,
|
|||||||
if (!key_table)
|
if (!key_table)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
rel->current_field = field;
|
relation->current_field = field;
|
||||||
|
|
||||||
g_hash_table_foreach (key_table, g_relation_delete_tuple, rel);
|
g_hash_table_foreach (key_table, g_relation_delete_tuple, relation);
|
||||||
|
|
||||||
g_hash_table_remove (table, key);
|
g_hash_table_remove (table, key);
|
||||||
|
|
||||||
@@ -269,7 +263,7 @@ g_relation_delete (GRelation *relation,
|
|||||||
|
|
||||||
/* @@@ FIXME: Remove empty hash tables. */
|
/* @@@ FIXME: Remove empty hash tables. */
|
||||||
|
|
||||||
return count - rel->count;
|
return count - relation->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -295,8 +289,7 @@ g_relation_select (GRelation *relation,
|
|||||||
gconstpointer key,
|
gconstpointer key,
|
||||||
gint field)
|
gint field)
|
||||||
{
|
{
|
||||||
GRealRelation *rel = (GRealRelation *) relation;
|
GHashTable *table = relation->hashed_tuple_tables[field];
|
||||||
GHashTable *table = rel->hashed_tuple_tables[field];
|
|
||||||
GHashTable *key_table;
|
GHashTable *key_table;
|
||||||
GRealTuples *tuples = g_new0 (GRealTuples, 1);
|
GRealTuples *tuples = g_new0 (GRealTuples, 1);
|
||||||
gint count;
|
gint count;
|
||||||
@@ -311,8 +304,8 @@ g_relation_select (GRelation *relation,
|
|||||||
|
|
||||||
count = g_relation_count (relation, key, field);
|
count = g_relation_count (relation, key, field);
|
||||||
|
|
||||||
tuples->data = g_malloc (sizeof (gpointer) * rel->fields * count);
|
tuples->data = g_malloc (sizeof (gpointer) * relation->fields * count);
|
||||||
tuples->width = rel->fields;
|
tuples->width = relation->fields;
|
||||||
|
|
||||||
g_hash_table_foreach (key_table, g_relation_select_tuple, tuples);
|
g_hash_table_foreach (key_table, g_relation_select_tuple, tuples);
|
||||||
|
|
||||||
@@ -326,8 +319,7 @@ g_relation_count (GRelation *relation,
|
|||||||
gconstpointer key,
|
gconstpointer key,
|
||||||
gint field)
|
gint field)
|
||||||
{
|
{
|
||||||
GRealRelation *rel = (GRealRelation *) relation;
|
GHashTable *table = relation->hashed_tuple_tables[field];
|
||||||
GHashTable *table = rel->hashed_tuple_tables[field];
|
|
||||||
GHashTable *key_table;
|
GHashTable *key_table;
|
||||||
|
|
||||||
g_return_val_if_fail (relation != NULL, 0);
|
g_return_val_if_fail (relation != NULL, 0);
|
||||||
@@ -344,22 +336,21 @@ g_relation_count (GRelation *relation,
|
|||||||
gboolean
|
gboolean
|
||||||
g_relation_exists (GRelation *relation, ...)
|
g_relation_exists (GRelation *relation, ...)
|
||||||
{
|
{
|
||||||
GRealRelation *rel = (GRealRelation *) relation;
|
gpointer* tuple = g_chunk_new (gpointer, relation->tuple_chunk);
|
||||||
gpointer* tuple = g_chunk_new (gpointer, rel->tuple_chunk);
|
|
||||||
va_list args;
|
va_list args;
|
||||||
gint i;
|
gint i;
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
va_start(args, relation);
|
va_start(args, relation);
|
||||||
|
|
||||||
for (i = 0; i < rel->fields; i += 1)
|
for (i = 0; i < relation->fields; i += 1)
|
||||||
tuple[i] = va_arg(args, gpointer);
|
tuple[i] = va_arg(args, gpointer);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
result = g_hash_table_lookup (rel->all_tuples, tuple) != NULL;
|
result = g_hash_table_lookup (relation->all_tuples, tuple) != NULL;
|
||||||
|
|
||||||
g_mem_chunk_free (rel->tuple_chunk, tuple);
|
g_mem_chunk_free (relation->tuple_chunk, tuple);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -399,7 +390,7 @@ g_relation_print_one (gpointer tuple_key,
|
|||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
GString *gstring;
|
GString *gstring;
|
||||||
GRealRelation* rel = (GRealRelation*) user_data;
|
GRelation* rel = (GRelation*) user_data;
|
||||||
gpointer* tuples = (gpointer*) tuple_value;
|
gpointer* tuples = (gpointer*) tuple_value;
|
||||||
|
|
||||||
gstring = g_string_new ("[");
|
gstring = g_string_new ("[");
|
||||||
@@ -422,7 +413,7 @@ g_relation_print_index (gpointer tuple_key,
|
|||||||
gpointer tuple_value,
|
gpointer tuple_value,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GRealRelation* rel = (GRealRelation*) user_data;
|
GRelation* rel = (GRelation*) user_data;
|
||||||
GHashTable* table = (GHashTable*) tuple_value;
|
GHashTable* table = (GHashTable*) tuple_value;
|
||||||
|
|
||||||
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** key %p", tuple_key);
|
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** key %p", tuple_key);
|
||||||
@@ -436,24 +427,23 @@ void
|
|||||||
g_relation_print (GRelation *relation)
|
g_relation_print (GRelation *relation)
|
||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
GRealRelation* rel = (GRealRelation*) relation;
|
|
||||||
|
|
||||||
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** all tuples (%d)", rel->count);
|
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** all tuples (%d)", relation->count);
|
||||||
|
|
||||||
g_hash_table_foreach (rel->all_tuples,
|
g_hash_table_foreach (relation->all_tuples,
|
||||||
g_relation_print_one,
|
g_relation_print_one,
|
||||||
rel);
|
relation);
|
||||||
|
|
||||||
for (i = 0; i < rel->fields; i += 1)
|
for (i = 0; i < relation->fields; i += 1)
|
||||||
{
|
{
|
||||||
if (rel->hashed_tuple_tables[i] == NULL)
|
if (relation->hashed_tuple_tables[i] == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** index %d", i);
|
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** index %d", i);
|
||||||
|
|
||||||
g_hash_table_foreach (rel->hashed_tuple_tables[i],
|
g_hash_table_foreach (relation->hashed_tuple_tables[i],
|
||||||
g_relation_print_index,
|
g_relation_print_index,
|
||||||
rel);
|
relation);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
140
glib/gstring.c
140
glib/gstring.c
@@ -42,10 +42,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "glib.h"
|
#include "glib.h"
|
||||||
|
|
||||||
typedef struct _GRealStringChunk GRealStringChunk;
|
struct _GStringChunk
|
||||||
typedef struct _GRealString GRealString;
|
|
||||||
|
|
||||||
struct _GRealStringChunk
|
|
||||||
{
|
{
|
||||||
GHashTable *const_table;
|
GHashTable *const_table;
|
||||||
GSList *storage_list;
|
GSList *storage_list;
|
||||||
@@ -54,13 +51,6 @@ struct _GRealStringChunk
|
|||||||
gsize default_size;
|
gsize default_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GRealString
|
|
||||||
{
|
|
||||||
gchar *str;
|
|
||||||
gsize len;
|
|
||||||
gsize allocated_len;
|
|
||||||
};
|
|
||||||
|
|
||||||
G_LOCK_DEFINE_STATIC (string_mem_chunk);
|
G_LOCK_DEFINE_STATIC (string_mem_chunk);
|
||||||
static GMemChunk *string_mem_chunk = NULL;
|
static GMemChunk *string_mem_chunk = NULL;
|
||||||
|
|
||||||
@@ -117,7 +107,7 @@ nearest_power (gsize base, gsize num)
|
|||||||
GStringChunk*
|
GStringChunk*
|
||||||
g_string_chunk_new (gsize default_size)
|
g_string_chunk_new (gsize default_size)
|
||||||
{
|
{
|
||||||
GRealStringChunk *new_chunk = g_new (GRealStringChunk, 1);
|
GStringChunk *new_chunk = g_new (GStringChunk, 1);
|
||||||
gsize size = 1;
|
gsize size = 1;
|
||||||
|
|
||||||
size = nearest_power (1, default_size);
|
size = nearest_power (1, default_size);
|
||||||
@@ -128,13 +118,12 @@ g_string_chunk_new (gsize default_size)
|
|||||||
new_chunk->default_size = size;
|
new_chunk->default_size = size;
|
||||||
new_chunk->this_size = size;
|
new_chunk->this_size = size;
|
||||||
|
|
||||||
return (GStringChunk*) new_chunk;
|
return new_chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_string_chunk_free (GStringChunk *fchunk)
|
g_string_chunk_free (GStringChunk *chunk)
|
||||||
{
|
{
|
||||||
GRealStringChunk *chunk = (GRealStringChunk*) fchunk;
|
|
||||||
GSList *tmp_list;
|
GSList *tmp_list;
|
||||||
|
|
||||||
g_return_if_fail (chunk != NULL);
|
g_return_if_fail (chunk != NULL);
|
||||||
@@ -154,10 +143,9 @@ g_string_chunk_free (GStringChunk *fchunk)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
g_string_chunk_insert (GStringChunk *fchunk,
|
g_string_chunk_insert (GStringChunk *chunk,
|
||||||
const gchar *string)
|
const gchar *string)
|
||||||
{
|
{
|
||||||
GRealStringChunk *chunk = (GRealStringChunk*) fchunk;
|
|
||||||
gsize len = strlen (string);
|
gsize len = strlen (string);
|
||||||
char* pos;
|
char* pos;
|
||||||
|
|
||||||
@@ -184,10 +172,9 @@ g_string_chunk_insert (GStringChunk *fchunk,
|
|||||||
}
|
}
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
g_string_chunk_insert_const (GStringChunk *fchunk,
|
g_string_chunk_insert_const (GStringChunk *chunk,
|
||||||
const gchar *string)
|
const gchar *string)
|
||||||
{
|
{
|
||||||
GRealStringChunk *chunk = (GRealStringChunk*) fchunk;
|
|
||||||
char* lookup;
|
char* lookup;
|
||||||
|
|
||||||
g_return_val_if_fail (chunk != NULL, NULL);
|
g_return_val_if_fail (chunk != NULL, NULL);
|
||||||
@@ -199,7 +186,7 @@ g_string_chunk_insert_const (GStringChunk *fchunk,
|
|||||||
|
|
||||||
if (!lookup)
|
if (!lookup)
|
||||||
{
|
{
|
||||||
lookup = g_string_chunk_insert (fchunk, string);
|
lookup = g_string_chunk_insert (chunk, string);
|
||||||
g_hash_table_insert (chunk->const_table, lookup, lookup);
|
g_hash_table_insert (chunk->const_table, lookup, lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,8 +196,8 @@ g_string_chunk_insert_const (GStringChunk *fchunk,
|
|||||||
/* Strings.
|
/* Strings.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
g_string_maybe_expand (GRealString* string,
|
g_string_maybe_expand (GString* string,
|
||||||
gsize len)
|
gsize len)
|
||||||
{
|
{
|
||||||
if (string->len + len >= string->allocated_len)
|
if (string->len + len >= string->allocated_len)
|
||||||
{
|
{
|
||||||
@@ -222,15 +209,15 @@ g_string_maybe_expand (GRealString* string,
|
|||||||
GString*
|
GString*
|
||||||
g_string_sized_new (gsize dfl_size)
|
g_string_sized_new (gsize dfl_size)
|
||||||
{
|
{
|
||||||
GRealString *string;
|
GString *string;
|
||||||
|
|
||||||
G_LOCK (string_mem_chunk);
|
G_LOCK (string_mem_chunk);
|
||||||
if (!string_mem_chunk)
|
if (!string_mem_chunk)
|
||||||
string_mem_chunk = g_mem_chunk_new ("string mem chunk",
|
string_mem_chunk = g_mem_chunk_new ("string mem chunk",
|
||||||
sizeof (GRealString),
|
sizeof (GString),
|
||||||
1024, G_ALLOC_AND_FREE);
|
1024, G_ALLOC_AND_FREE);
|
||||||
|
|
||||||
string = g_chunk_new (GRealString, string_mem_chunk);
|
string = g_chunk_new (GString, string_mem_chunk);
|
||||||
G_UNLOCK (string_mem_chunk);
|
G_UNLOCK (string_mem_chunk);
|
||||||
|
|
||||||
string->allocated_len = 0;
|
string->allocated_len = 0;
|
||||||
@@ -240,7 +227,7 @@ g_string_sized_new (gsize dfl_size)
|
|||||||
g_string_maybe_expand (string, MAX (dfl_size, 2));
|
g_string_maybe_expand (string, MAX (dfl_size, 2));
|
||||||
string->str[0] = 0;
|
string->str[0] = 0;
|
||||||
|
|
||||||
return (GString*) string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
@@ -303,8 +290,8 @@ g_string_equal (const GString *v,
|
|||||||
const GString *v2)
|
const GString *v2)
|
||||||
{
|
{
|
||||||
gchar *p, *q;
|
gchar *p, *q;
|
||||||
GRealString *string1 = (GRealString *) v;
|
GString *string1 = (GString *) v;
|
||||||
GRealString *string2 = (GRealString *) v2;
|
GString *string2 = (GString *) v2;
|
||||||
gsize i = string1->len;
|
gsize i = string1->len;
|
||||||
|
|
||||||
if (i != string2->len)
|
if (i != string2->len)
|
||||||
@@ -354,18 +341,15 @@ g_string_assign (GString *string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_truncate (GString *fstring,
|
g_string_truncate (GString *string,
|
||||||
gsize len)
|
gsize len)
|
||||||
{
|
{
|
||||||
GRealString *string = (GRealString *) fstring;
|
|
||||||
|
|
||||||
g_return_val_if_fail (string != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
string->len = MIN (len, string->len);
|
string->len = MIN (len, string->len);
|
||||||
|
|
||||||
string->str[string->len] = 0;
|
string->str[string->len] = 0;
|
||||||
|
|
||||||
return fstring;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -379,35 +363,31 @@ g_string_truncate (GString *fstring,
|
|||||||
* of the newly added area are undefined. (However, as
|
* of the newly added area are undefined. (However, as
|
||||||
* always, string->str[string->len] will be a nul byte.)
|
* always, string->str[string->len] will be a nul byte.)
|
||||||
*
|
*
|
||||||
* Return value: @fstring
|
* Return value: @string
|
||||||
**/
|
**/
|
||||||
GString*
|
GString*
|
||||||
g_string_set_size (GString *string,
|
g_string_set_size (GString *string,
|
||||||
gsize len)
|
gsize len)
|
||||||
{
|
{
|
||||||
GRealString *rstring = (GRealString *) string;
|
|
||||||
|
|
||||||
g_return_val_if_fail (string != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
if (len >= rstring->allocated_len)
|
if (len >= string->allocated_len)
|
||||||
g_string_maybe_expand (rstring, len - string->len);
|
g_string_maybe_expand (string, len - string->len);
|
||||||
|
|
||||||
rstring->len = len;
|
string->len = len;
|
||||||
rstring->str[len] = 0;
|
string->str[len] = 0;
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_insert_len (GString *fstring,
|
g_string_insert_len (GString *string,
|
||||||
gssize pos,
|
gssize pos,
|
||||||
const gchar *val,
|
const gchar *val,
|
||||||
gssize len)
|
gssize len)
|
||||||
{
|
{
|
||||||
GRealString *string = (GRealString *) fstring;
|
|
||||||
|
|
||||||
g_return_val_if_fail (string != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
g_return_val_if_fail (val != NULL, fstring);
|
g_return_val_if_fail (val != NULL, string);
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen (val);
|
len = strlen (val);
|
||||||
@@ -415,7 +395,7 @@ g_string_insert_len (GString *fstring,
|
|||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
pos = string->len;
|
pos = string->len;
|
||||||
else
|
else
|
||||||
g_return_val_if_fail (pos <= string->len, fstring);
|
g_return_val_if_fail (pos <= string->len, string);
|
||||||
|
|
||||||
g_string_maybe_expand (string, len);
|
g_string_maybe_expand (string, len);
|
||||||
|
|
||||||
@@ -432,17 +412,17 @@ g_string_insert_len (GString *fstring,
|
|||||||
|
|
||||||
string->str[string->len] = 0;
|
string->str[string->len] = 0;
|
||||||
|
|
||||||
return fstring;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_append (GString *fstring,
|
g_string_append (GString *string,
|
||||||
const gchar *val)
|
const gchar *val)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (fstring != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
g_return_val_if_fail (val != NULL, fstring);
|
g_return_val_if_fail (val != NULL, string);
|
||||||
|
|
||||||
return g_string_insert_len (fstring, -1, val, -1);
|
return g_string_insert_len (string, -1, val, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
@@ -457,12 +437,12 @@ g_string_append_len (GString *string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_append_c (GString *fstring,
|
g_string_append_c (GString *string,
|
||||||
gchar c)
|
gchar c)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (fstring != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
return g_string_insert_c (fstring, -1, c);
|
return g_string_insert_c (string, -1, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -485,13 +465,13 @@ g_string_append_unichar (GString *string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_prepend (GString *fstring,
|
g_string_prepend (GString *string,
|
||||||
const gchar *val)
|
const gchar *val)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (fstring != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
g_return_val_if_fail (val != NULL, fstring);
|
g_return_val_if_fail (val != NULL, string);
|
||||||
|
|
||||||
return g_string_insert_len (fstring, 0, val, -1);
|
return g_string_insert_len (string, 0, val, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
@@ -506,12 +486,12 @@ g_string_prepend_len (GString *string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_prepend_c (GString *fstring,
|
g_string_prepend_c (GString *string,
|
||||||
gchar c)
|
gchar c)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (fstring != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
return g_string_insert_c (fstring, 0, c);
|
return g_string_insert_c (string, 0, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -534,25 +514,23 @@ g_string_prepend_unichar (GString *string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_insert (GString *fstring,
|
g_string_insert (GString *string,
|
||||||
gssize pos,
|
gssize pos,
|
||||||
const gchar *val)
|
const gchar *val)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (fstring != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
g_return_val_if_fail (val != NULL, fstring);
|
g_return_val_if_fail (val != NULL, string);
|
||||||
if (pos >= 0)
|
if (pos >= 0)
|
||||||
g_return_val_if_fail (pos <= fstring->len, fstring);
|
g_return_val_if_fail (pos <= string->len, string);
|
||||||
|
|
||||||
return g_string_insert_len (fstring, pos, val, -1);
|
return g_string_insert_len (string, pos, val, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_insert_c (GString *fstring,
|
g_string_insert_c (GString *string,
|
||||||
gssize pos,
|
gssize pos,
|
||||||
gchar c)
|
gchar c)
|
||||||
{
|
{
|
||||||
GRealString *string = (GRealString *) fstring;
|
|
||||||
|
|
||||||
g_return_val_if_fail (string != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
g_string_maybe_expand (string, 1);
|
g_string_maybe_expand (string, 1);
|
||||||
@@ -560,7 +538,7 @@ g_string_insert_c (GString *fstring,
|
|||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
pos = string->len;
|
pos = string->len;
|
||||||
else
|
else
|
||||||
g_return_val_if_fail (pos <= string->len, fstring);
|
g_return_val_if_fail (pos <= string->len, string);
|
||||||
|
|
||||||
/* If not just an append, move the old stuff */
|
/* If not just an append, move the old stuff */
|
||||||
if (pos < string->len)
|
if (pos < string->len)
|
||||||
@@ -572,7 +550,7 @@ g_string_insert_c (GString *fstring,
|
|||||||
|
|
||||||
string->str[string->len] = 0;
|
string->str[string->len] = 0;
|
||||||
|
|
||||||
return fstring;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -606,21 +584,19 @@ g_string_insert_unichar (GString *string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_erase (GString *fstring,
|
g_string_erase (GString *string,
|
||||||
gsize pos,
|
gsize pos,
|
||||||
gsize len)
|
gsize len)
|
||||||
{
|
{
|
||||||
GRealString *string = (GRealString*)fstring;
|
|
||||||
|
|
||||||
g_return_val_if_fail (string != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
g_return_val_if_fail (pos >= 0, fstring);
|
g_return_val_if_fail (pos >= 0, string);
|
||||||
g_return_val_if_fail (pos <= string->len, fstring);
|
g_return_val_if_fail (pos <= string->len, string);
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = string->len - pos;
|
len = string->len - pos;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (pos + len <= string->len, fstring);
|
g_return_val_if_fail (pos + len <= string->len, string);
|
||||||
|
|
||||||
if (pos + len < string->len)
|
if (pos + len < string->len)
|
||||||
g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
|
g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
|
||||||
@@ -630,7 +606,7 @@ g_string_erase (GString *fstring,
|
|||||||
|
|
||||||
string->str[string->len] = 0;
|
string->str[string->len] = 0;
|
||||||
|
|
||||||
return fstring;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -694,9 +670,8 @@ g_string_ascii_up (GString *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_down (GString *fstring)
|
g_string_down (GString *string)
|
||||||
{
|
{
|
||||||
GRealString *string = (GRealString *) fstring;
|
|
||||||
guchar *s;
|
guchar *s;
|
||||||
glong n = string->len;
|
glong n = string->len;
|
||||||
|
|
||||||
@@ -712,13 +687,12 @@ g_string_down (GString *fstring)
|
|||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fstring;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
GString*
|
GString*
|
||||||
g_string_up (GString *fstring)
|
g_string_up (GString *string)
|
||||||
{
|
{
|
||||||
GRealString *string = (GRealString *) fstring;
|
|
||||||
guchar *s;
|
guchar *s;
|
||||||
glong n = string->len;
|
glong n = string->len;
|
||||||
|
|
||||||
@@ -734,7 +708,7 @@ g_string_up (GString *fstring)
|
|||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fstring;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -46,9 +46,7 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif /* G_OS_WIN32 */
|
#endif /* G_OS_WIN32 */
|
||||||
|
|
||||||
typedef struct _GRealTimer GRealTimer;
|
struct _GTimer
|
||||||
|
|
||||||
struct _GRealTimer
|
|
||||||
{
|
{
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
DWORD start;
|
DWORD start;
|
||||||
@@ -72,14 +70,14 @@ struct _GRealTimer
|
|||||||
GTimer*
|
GTimer*
|
||||||
g_timer_new (void)
|
g_timer_new (void)
|
||||||
{
|
{
|
||||||
GRealTimer *timer;
|
GTimer *timer;
|
||||||
|
|
||||||
timer = g_new (GRealTimer, 1);
|
timer = g_new (GTimer, 1);
|
||||||
timer->active = TRUE;
|
timer->active = TRUE;
|
||||||
|
|
||||||
GETTIME (timer->start);
|
GETTIME (timer->start);
|
||||||
|
|
||||||
return ((GTimer*) timer);
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -93,46 +91,35 @@ g_timer_destroy (GTimer *timer)
|
|||||||
void
|
void
|
||||||
g_timer_start (GTimer *timer)
|
g_timer_start (GTimer *timer)
|
||||||
{
|
{
|
||||||
GRealTimer *rtimer;
|
|
||||||
|
|
||||||
g_return_if_fail (timer != NULL);
|
g_return_if_fail (timer != NULL);
|
||||||
|
|
||||||
rtimer = (GRealTimer*) timer;
|
timer->active = TRUE;
|
||||||
rtimer->active = TRUE;
|
|
||||||
|
|
||||||
GETTIME (rtimer->start);
|
GETTIME (timer->start);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_timer_stop (GTimer *timer)
|
g_timer_stop (GTimer *timer)
|
||||||
{
|
{
|
||||||
GRealTimer *rtimer;
|
|
||||||
|
|
||||||
g_return_if_fail (timer != NULL);
|
g_return_if_fail (timer != NULL);
|
||||||
|
|
||||||
rtimer = (GRealTimer*) timer;
|
timer->active = FALSE;
|
||||||
rtimer->active = FALSE;
|
|
||||||
|
|
||||||
GETTIME(rtimer->end);
|
GETTIME(timer->end);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_timer_reset (GTimer *timer)
|
g_timer_reset (GTimer *timer)
|
||||||
{
|
{
|
||||||
GRealTimer *rtimer;
|
|
||||||
|
|
||||||
g_return_if_fail (timer != NULL);
|
g_return_if_fail (timer != NULL);
|
||||||
|
|
||||||
rtimer = (GRealTimer*) timer;
|
GETTIME (timer->start);
|
||||||
|
|
||||||
GETTIME (rtimer->start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gdouble
|
gdouble
|
||||||
g_timer_elapsed (GTimer *timer,
|
g_timer_elapsed (GTimer *timer,
|
||||||
gulong *microseconds)
|
gulong *microseconds)
|
||||||
{
|
{
|
||||||
GRealTimer *rtimer;
|
|
||||||
gdouble total;
|
gdouble total;
|
||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
struct timeval elapsed;
|
struct timeval elapsed;
|
||||||
@@ -140,39 +127,37 @@ g_timer_elapsed (GTimer *timer,
|
|||||||
|
|
||||||
g_return_val_if_fail (timer != NULL, 0);
|
g_return_val_if_fail (timer != NULL, 0);
|
||||||
|
|
||||||
rtimer = (GRealTimer*) timer;
|
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
if (rtimer->active)
|
if (timer->active)
|
||||||
rtimer->end = GetTickCount ();
|
timer->end = GetTickCount ();
|
||||||
|
|
||||||
/* Check for wraparound, which happens every 49.7 days. */
|
/* Check for wraparound, which happens every 49.7 days. */
|
||||||
if (rtimer->end < rtimer->start)
|
if (timer->end < timer->start)
|
||||||
total = (UINT_MAX - (rtimer->start - rtimer->end)) / 1000.0;
|
total = (UINT_MAX - (timer->start - timer->end)) / 1000.0;
|
||||||
else
|
else
|
||||||
total = (rtimer->end - rtimer->start) / 1000.0;
|
total = (timer->end - timer->start) / 1000.0;
|
||||||
|
|
||||||
if (microseconds)
|
if (microseconds)
|
||||||
{
|
{
|
||||||
if (rtimer->end < rtimer->start)
|
if (timer->end < timer->start)
|
||||||
*microseconds =
|
*microseconds =
|
||||||
((UINT_MAX - (rtimer->start - rtimer->end)) % 1000) * 1000;
|
((UINT_MAX - (timer->start - timer->end)) % 1000) * 1000;
|
||||||
else
|
else
|
||||||
*microseconds =
|
*microseconds =
|
||||||
((rtimer->end - rtimer->start) % 1000) * 1000;
|
((timer->end - timer->start) % 1000) * 1000;
|
||||||
}
|
}
|
||||||
#else /* !G_OS_WIN32 */
|
#else /* !G_OS_WIN32 */
|
||||||
if (rtimer->active)
|
if (timer->active)
|
||||||
gettimeofday (&rtimer->end, NULL);
|
gettimeofday (&timer->end, NULL);
|
||||||
|
|
||||||
if (rtimer->start.tv_usec > rtimer->end.tv_usec)
|
if (timer->start.tv_usec > timer->end.tv_usec)
|
||||||
{
|
{
|
||||||
rtimer->end.tv_usec += G_USEC_PER_SEC;
|
timer->end.tv_usec += G_USEC_PER_SEC;
|
||||||
rtimer->end.tv_sec--;
|
timer->end.tv_sec--;
|
||||||
}
|
}
|
||||||
|
|
||||||
elapsed.tv_usec = rtimer->end.tv_usec - rtimer->start.tv_usec;
|
elapsed.tv_usec = timer->end.tv_usec - timer->start.tv_usec;
|
||||||
elapsed.tv_sec = rtimer->end.tv_sec - rtimer->start.tv_sec;
|
elapsed.tv_sec = timer->end.tv_sec - timer->start.tv_sec;
|
||||||
|
|
||||||
total = elapsed.tv_sec + ((gdouble) elapsed.tv_usec / 1e6);
|
total = elapsed.tv_sec + ((gdouble) elapsed.tv_usec / 1e6);
|
||||||
if (total < 0)
|
if (total < 0)
|
||||||
|
153
glib/gtree.c
153
glib/gtree.c
@@ -35,10 +35,9 @@
|
|||||||
#include "glib.h"
|
#include "glib.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GRealTree GRealTree;
|
|
||||||
typedef struct _GTreeNode GTreeNode;
|
typedef struct _GTreeNode GTreeNode;
|
||||||
|
|
||||||
struct _GRealTree
|
struct _GTree
|
||||||
{
|
{
|
||||||
GTreeNode *root;
|
GTreeNode *root;
|
||||||
GCompareDataFunc key_compare;
|
GCompareDataFunc key_compare;
|
||||||
@@ -235,18 +234,18 @@ g_tree_new_full (GCompareDataFunc key_compare_func,
|
|||||||
GDestroyNotify key_destroy_func,
|
GDestroyNotify key_destroy_func,
|
||||||
GDestroyNotify value_destroy_func)
|
GDestroyNotify value_destroy_func)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
GTree *tree;
|
||||||
|
|
||||||
g_return_val_if_fail (key_compare_func != NULL, NULL);
|
g_return_val_if_fail (key_compare_func != NULL, NULL);
|
||||||
|
|
||||||
rtree = g_new (GRealTree, 1);
|
tree = g_new (GTree, 1);
|
||||||
rtree->root = NULL;
|
tree->root = NULL;
|
||||||
rtree->key_compare = key_compare_func;
|
tree->key_compare = key_compare_func;
|
||||||
rtree->key_destroy_func = key_destroy_func;
|
tree->key_destroy_func = key_destroy_func;
|
||||||
rtree->value_destroy_func = value_destroy_func;
|
tree->value_destroy_func = value_destroy_func;
|
||||||
rtree->key_compare_data = key_compare_data;
|
tree->key_compare_data = key_compare_data;
|
||||||
|
|
||||||
return (GTree*) rtree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -261,17 +260,13 @@ g_tree_new_full (GCompareDataFunc key_compare_func,
|
|||||||
void
|
void
|
||||||
g_tree_destroy (GTree *tree)
|
g_tree_destroy (GTree *tree)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
|
|
||||||
g_return_if_fail (tree != NULL);
|
g_return_if_fail (tree != NULL);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
g_tree_node_destroy (tree->root,
|
||||||
|
tree->key_destroy_func,
|
||||||
|
tree->value_destroy_func);
|
||||||
|
|
||||||
g_tree_node_destroy (rtree->root,
|
g_free (tree);
|
||||||
rtree->key_destroy_func,
|
|
||||||
rtree->value_destroy_func);
|
|
||||||
|
|
||||||
g_free (rtree);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -294,18 +289,15 @@ g_tree_insert (GTree *tree,
|
|||||||
gpointer key,
|
gpointer key,
|
||||||
gpointer value)
|
gpointer value)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
gboolean inserted;
|
gboolean inserted;
|
||||||
|
|
||||||
g_return_if_fail (tree != NULL);
|
g_return_if_fail (tree != NULL);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
|
||||||
|
|
||||||
inserted = FALSE;
|
inserted = FALSE;
|
||||||
rtree->root = g_tree_node_insert (tree,
|
tree->root = g_tree_node_insert (tree,
|
||||||
rtree->root,
|
tree->root,
|
||||||
key, value,
|
key, value,
|
||||||
FALSE, &inserted);
|
FALSE, &inserted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -329,18 +321,15 @@ g_tree_replace (GTree *tree,
|
|||||||
gpointer key,
|
gpointer key,
|
||||||
gpointer value)
|
gpointer value)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
gboolean inserted;
|
gboolean inserted;
|
||||||
|
|
||||||
g_return_if_fail (tree != NULL);
|
g_return_if_fail (tree != NULL);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
|
||||||
|
|
||||||
inserted = FALSE;
|
inserted = FALSE;
|
||||||
rtree->root = g_tree_node_insert (tree,
|
tree->root = g_tree_node_insert (tree,
|
||||||
rtree->root,
|
tree->root,
|
||||||
key, value,
|
key, value,
|
||||||
TRUE, &inserted);
|
TRUE, &inserted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -358,13 +347,9 @@ void
|
|||||||
g_tree_remove (GTree *tree,
|
g_tree_remove (GTree *tree,
|
||||||
gconstpointer key)
|
gconstpointer key)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
|
|
||||||
g_return_if_fail (tree != NULL);
|
g_return_if_fail (tree != NULL);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
tree->root = g_tree_node_remove (tree, tree->root, key, TRUE);
|
||||||
|
|
||||||
rtree->root = g_tree_node_remove (tree, rtree->root, key, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -379,13 +364,9 @@ void
|
|||||||
g_tree_steal (GTree *tree,
|
g_tree_steal (GTree *tree,
|
||||||
gconstpointer key)
|
gconstpointer key)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
|
|
||||||
g_return_if_fail (tree != NULL);
|
g_return_if_fail (tree != NULL);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
tree->root = g_tree_node_remove (tree, tree->root, key, FALSE);
|
||||||
|
|
||||||
rtree->root = g_tree_node_remove (tree, rtree->root, key, FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -403,15 +384,12 @@ gpointer
|
|||||||
g_tree_lookup (GTree *tree,
|
g_tree_lookup (GTree *tree,
|
||||||
gconstpointer key)
|
gconstpointer key)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
GTreeNode *node;
|
GTreeNode *node;
|
||||||
|
|
||||||
g_return_val_if_fail (tree != NULL, NULL);
|
g_return_val_if_fail (tree != NULL, NULL);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
node = g_tree_node_lookup (tree->root,
|
||||||
|
tree->key_compare, tree->key_compare_data, key);
|
||||||
node = g_tree_node_lookup (rtree->root,
|
|
||||||
rtree->key_compare, rtree->key_compare_data, key);
|
|
||||||
|
|
||||||
return node ? node->value : NULL;
|
return node ? node->value : NULL;
|
||||||
}
|
}
|
||||||
@@ -436,15 +414,12 @@ g_tree_lookup_extended (GTree *tree,
|
|||||||
gpointer *orig_key,
|
gpointer *orig_key,
|
||||||
gpointer *value)
|
gpointer *value)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
GTreeNode *node;
|
GTreeNode *node;
|
||||||
|
|
||||||
g_return_val_if_fail (tree != NULL, FALSE);
|
g_return_val_if_fail (tree != NULL, FALSE);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
node = g_tree_node_lookup (tree->root,
|
||||||
|
tree->key_compare, tree->key_compare_data, lookup_key);
|
||||||
node = g_tree_node_lookup (rtree->root,
|
|
||||||
rtree->key_compare, rtree->key_compare_data, lookup_key);
|
|
||||||
|
|
||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
@@ -474,16 +449,12 @@ g_tree_foreach (GTree *tree,
|
|||||||
GTraverseFunc func,
|
GTraverseFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
|
|
||||||
g_return_if_fail (tree != NULL);
|
g_return_if_fail (tree != NULL);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
if (!tree->root)
|
||||||
|
|
||||||
if (!rtree->root)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_tree_node_in_order (rtree->root, func, user_data);
|
g_tree_node_in_order (tree->root, func, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -504,27 +475,23 @@ g_tree_traverse (GTree *tree,
|
|||||||
GTraverseType traverse_type,
|
GTraverseType traverse_type,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
|
|
||||||
g_return_if_fail (tree != NULL);
|
g_return_if_fail (tree != NULL);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
if (!tree->root)
|
||||||
|
|
||||||
if (!rtree->root)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (traverse_type)
|
switch (traverse_type)
|
||||||
{
|
{
|
||||||
case G_PRE_ORDER:
|
case G_PRE_ORDER:
|
||||||
g_tree_node_pre_order (rtree->root, traverse_func, user_data);
|
g_tree_node_pre_order (tree->root, traverse_func, user_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case G_IN_ORDER:
|
case G_IN_ORDER:
|
||||||
g_tree_node_in_order (rtree->root, traverse_func, user_data);
|
g_tree_node_in_order (tree->root, traverse_func, user_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case G_POST_ORDER:
|
case G_POST_ORDER:
|
||||||
g_tree_node_post_order (rtree->root, traverse_func, user_data);
|
g_tree_node_post_order (tree->root, traverse_func, user_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case G_LEVEL_ORDER:
|
case G_LEVEL_ORDER:
|
||||||
@@ -560,14 +527,10 @@ g_tree_search (GTree *tree,
|
|||||||
GCompareFunc search_func,
|
GCompareFunc search_func,
|
||||||
gconstpointer user_data)
|
gconstpointer user_data)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
|
|
||||||
g_return_val_if_fail (tree != NULL, NULL);
|
g_return_val_if_fail (tree != NULL, NULL);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
if (tree->root)
|
||||||
|
return g_tree_node_search (tree->root, search_func, user_data);
|
||||||
if (rtree->root)
|
|
||||||
return g_tree_node_search (rtree->root, search_func, user_data);
|
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -587,14 +550,10 @@ g_tree_search (GTree *tree,
|
|||||||
gint
|
gint
|
||||||
g_tree_height (GTree *tree)
|
g_tree_height (GTree *tree)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
|
|
||||||
g_return_val_if_fail (tree != NULL, 0);
|
g_return_val_if_fail (tree != NULL, 0);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
if (tree->root)
|
||||||
|
return g_tree_node_height (tree->root);
|
||||||
if (rtree->root)
|
|
||||||
return g_tree_node_height (rtree->root);
|
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -610,14 +569,10 @@ g_tree_height (GTree *tree)
|
|||||||
gint
|
gint
|
||||||
g_tree_nnodes (GTree *tree)
|
g_tree_nnodes (GTree *tree)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
|
|
||||||
g_return_val_if_fail (tree != NULL, 0);
|
g_return_val_if_fail (tree != NULL, 0);
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
if (tree->root)
|
||||||
|
return g_tree_node_count (tree->root);
|
||||||
if (rtree->root)
|
|
||||||
return g_tree_node_count (rtree->root);
|
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -630,40 +585,37 @@ g_tree_node_insert (GTree *tree,
|
|||||||
gboolean replace,
|
gboolean replace,
|
||||||
gboolean *inserted)
|
gboolean *inserted)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
gint old_balance;
|
gint old_balance;
|
||||||
gint cmp;
|
gint cmp;
|
||||||
|
|
||||||
rtree = (GRealTree*) tree;
|
|
||||||
|
|
||||||
if (!node)
|
if (!node)
|
||||||
{
|
{
|
||||||
*inserted = TRUE;
|
*inserted = TRUE;
|
||||||
return g_tree_node_new (key, value);
|
return g_tree_node_new (key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmp = rtree->key_compare (key, node->key, rtree->key_compare_data);
|
cmp = tree->key_compare (key, node->key, tree->key_compare_data);
|
||||||
if (cmp == 0)
|
if (cmp == 0)
|
||||||
{
|
{
|
||||||
*inserted = FALSE;
|
*inserted = FALSE;
|
||||||
|
|
||||||
if (rtree->value_destroy_func)
|
if (tree->value_destroy_func)
|
||||||
rtree->value_destroy_func (node->value);
|
tree->value_destroy_func (node->value);
|
||||||
|
|
||||||
node->value = value;
|
node->value = value;
|
||||||
|
|
||||||
if (replace)
|
if (replace)
|
||||||
{
|
{
|
||||||
if (rtree->key_destroy_func)
|
if (tree->key_destroy_func)
|
||||||
rtree->key_destroy_func (node->key);
|
tree->key_destroy_func (node->key);
|
||||||
|
|
||||||
node->key = key;
|
node->key = key;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* free the passed key */
|
/* free the passed key */
|
||||||
if (rtree->key_destroy_func)
|
if (tree->key_destroy_func)
|
||||||
rtree->key_destroy_func (key);
|
tree->key_destroy_func (key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
@@ -725,7 +677,6 @@ g_tree_node_remove (GTree *tree,
|
|||||||
gconstpointer key,
|
gconstpointer key,
|
||||||
gboolean notify)
|
gboolean notify)
|
||||||
{
|
{
|
||||||
GRealTree *rtree;
|
|
||||||
GTreeNode *new_root;
|
GTreeNode *new_root;
|
||||||
gint old_balance;
|
gint old_balance;
|
||||||
gint cmp;
|
gint cmp;
|
||||||
@@ -733,9 +684,7 @@ g_tree_node_remove (GTree *tree,
|
|||||||
if (!node)
|
if (!node)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
rtree = (GRealTree *) tree;
|
cmp = tree->key_compare (key, node->key, tree->key_compare_data);
|
||||||
|
|
||||||
cmp = rtree->key_compare (key, node->key, rtree->key_compare_data);
|
|
||||||
if (cmp == 0)
|
if (cmp == 0)
|
||||||
{
|
{
|
||||||
GTreeNode *garbage;
|
GTreeNode *garbage;
|
||||||
@@ -758,10 +707,10 @@ g_tree_node_remove (GTree *tree,
|
|||||||
|
|
||||||
if (notify)
|
if (notify)
|
||||||
{
|
{
|
||||||
if (rtree->key_destroy_func)
|
if (tree->key_destroy_func)
|
||||||
rtree->key_destroy_func (garbage->key);
|
tree->key_destroy_func (garbage->key);
|
||||||
if (rtree->value_destroy_func)
|
if (tree->value_destroy_func)
|
||||||
rtree->value_destroy_func (garbage->value);
|
tree->value_destroy_func (garbage->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_GC_FRIENDLY
|
#ifdef ENABLE_GC_FRIENDLY
|
||||||
|
Reference in New Issue
Block a user