mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
fix preallocation logic, support DISABLE_MEM_POOLS properly, group value
Sun Aug 12 02:07:10 2001 Tim Janik <timj@gtk.org> * gvaluearray.[hc]: fix preallocation logic, support DISABLE_MEM_POOLS properly, group value allocations. (g_value_array_new): fix semantic of n_prealloced argument, so it's really just about preallocation space.
This commit is contained in:
parent
6132f0496a
commit
4bc2b2c3b4
@ -1,3 +1,16 @@
|
||||
Sun Aug 12 02:07:10 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gvaluearray.[hc]: fix preallocation logic, support DISABLE_MEM_POOLS
|
||||
properly, group value allocations.
|
||||
(g_value_array_new): fix semantic of n_prealloced argument, so it's
|
||||
really just about preallocation space.
|
||||
|
||||
2001-07-23 Padraig O'Briain <Padraig.Obriain@Sun.COM>
|
||||
|
||||
* gobject/gobjectnotifyqueue.c: fix unconditional check of
|
||||
first GParamSpec in g_object_notify_queue_thaw(); to prevent
|
||||
property notification being lost.
|
||||
|
||||
2001-08-06 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* gobject.[ch]:
|
||||
|
@ -25,6 +25,11 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h> /* qsort() */
|
||||
|
||||
#ifdef DISABLE_MEM_POOLS
|
||||
# define GROUP_N_VALUES (1) /* power of 2 !! */
|
||||
#else
|
||||
# define GROUP_N_VALUES (8) /* power of 2 !! */
|
||||
#endif
|
||||
|
||||
|
||||
/* --- functions --- */
|
||||
@ -38,14 +43,49 @@ g_value_array_get_nth (GValueArray *value_array,
|
||||
return value_array->values + index;
|
||||
}
|
||||
|
||||
static inline void
|
||||
value_array_grow (GValueArray *value_array,
|
||||
guint n_values,
|
||||
gboolean zero_init)
|
||||
{
|
||||
g_return_if_fail (n_values >= value_array->n_values);
|
||||
|
||||
value_array->n_values = n_values;
|
||||
if (value_array->n_values > value_array->n_prealloced)
|
||||
{
|
||||
guint i = value_array->n_prealloced;
|
||||
|
||||
value_array->n_prealloced = (value_array->n_values + GROUP_N_VALUES - 1) & ~(GROUP_N_VALUES - 1);
|
||||
value_array->values = g_renew (GValue, value_array->values, value_array->n_prealloced);
|
||||
if (!zero_init)
|
||||
i = value_array->n_values;
|
||||
memset (value_array->values + i, 0,
|
||||
(value_array->n_prealloced - i) * sizeof (value_array->values[0]));
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
value_array_shrink (GValueArray *value_array)
|
||||
{
|
||||
#ifdef DISABLE_MEM_POOLS
|
||||
if (value_array->n_prealloced >= value_array->n_values + GROUP_N_VALUES)
|
||||
{
|
||||
value_array->n_prealloced = (value_array->n_values + GROUP_N_VALUES - 1) & ~(GROUP_N_VALUES - 1);
|
||||
value_array->values = g_renew (GValue, value_array->values, value_array->n_prealloced);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
GValueArray*
|
||||
g_value_array_new (guint n_prealloced)
|
||||
{
|
||||
GValueArray *value_array = g_new0 (GValueArray, 1);
|
||||
GValueArray *value_array = g_new (GValueArray, 1);
|
||||
|
||||
value_array->n_values = n_prealloced;
|
||||
value_array->values = g_renew (GValue, value_array->values, value_array->n_values);
|
||||
memset (value_array->values, 0, value_array->n_values * sizeof (value_array->values[0]));
|
||||
value_array->n_values = 0;
|
||||
value_array->n_prealloced = 0;
|
||||
value_array->values = NULL;
|
||||
value_array_grow (value_array, n_prealloced, TRUE);
|
||||
value_array->n_values = 0;
|
||||
|
||||
return value_array;
|
||||
}
|
||||
@ -76,10 +116,11 @@ g_value_array_copy (const GValueArray *value_array)
|
||||
|
||||
g_return_val_if_fail (value_array != NULL, NULL);
|
||||
|
||||
new_array = g_new0 (GValueArray, 1);
|
||||
new_array->n_values = value_array->n_values;
|
||||
new_array->values = g_renew (GValue, new_array->values, new_array->n_values);
|
||||
memset (new_array->values, 0, new_array->n_values * sizeof (new_array->values[0]));
|
||||
new_array = g_new (GValueArray, 1);
|
||||
new_array->n_values = 0;
|
||||
new_array->values = NULL;
|
||||
new_array->n_prealloced = 0;
|
||||
value_array_grow (new_array, value_array->n_values, TRUE);
|
||||
for (i = 0; i < new_array->n_values; i++)
|
||||
if (G_VALUE_TYPE (value_array->values + i) != 0)
|
||||
{
|
||||
@ -121,8 +162,8 @@ g_value_array_insert (GValueArray *value_array,
|
||||
|
||||
/* we support NULL for "value" as a shortcut for an unset value */
|
||||
|
||||
i = value_array->n_values++;
|
||||
value_array->values = g_renew (GValue, value_array->values, value_array->n_values);
|
||||
i = value_array->n_values;
|
||||
value_array_grow (value_array, value_array->n_values + 1, FALSE);
|
||||
if (index + 1 < value_array->n_values)
|
||||
g_memmove (value_array->values + index + 1, value_array->values + index,
|
||||
(i - index) * sizeof (value_array->values[0]));
|
||||
@ -148,7 +189,9 @@ g_value_array_remove (GValueArray *value_array,
|
||||
if (index < value_array->n_values)
|
||||
g_memmove (value_array->values + index, value_array->values + index + 1,
|
||||
(value_array->n_values - index) * sizeof (value_array->values[0]));
|
||||
value_array->values = g_renew (GValue, value_array->values, value_array->n_values);
|
||||
value_array_shrink (value_array);
|
||||
if (value_array->n_prealloced > value_array->n_values)
|
||||
memset (value_array->values + value_array->n_values, 0, sizeof (value_array->values[0]));
|
||||
|
||||
return value_array;
|
||||
}
|
||||
|
@ -36,6 +36,9 @@ struct _GValueArray
|
||||
{
|
||||
guint n_values;
|
||||
GValue *values;
|
||||
|
||||
/*< private >*/
|
||||
guint n_prealloced;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user