mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 14:36:16 +01:00
Put calls to registered copy/free functions into separate functions
This eases cleaning up these functions. One optimization in value_set_internal() was lost in the process. It shouldn't cause too many issues when all is said and done. https://bugzilla.gnome.org/show_bug.cgi?id=554887
This commit is contained in:
parent
4ecf8655b3
commit
ac666d2ae3
@ -307,6 +307,26 @@ g_byte_array_get_type (void)
|
|||||||
return type_id;
|
return type_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gpointer
|
||||||
|
_g_type_boxed_copy (GType type, gconstpointer value)
|
||||||
|
{
|
||||||
|
BoxedNode key, *node;
|
||||||
|
|
||||||
|
key.type = G_VALUE_TYPE (value);
|
||||||
|
node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
|
||||||
|
return node->copy (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_g_type_boxed_free (GType type, gpointer value)
|
||||||
|
{
|
||||||
|
BoxedNode key, *node;
|
||||||
|
|
||||||
|
key.type = G_VALUE_TYPE (value);
|
||||||
|
node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
|
||||||
|
node->free (value);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
boxed_proxy_value_init (GValue *value)
|
boxed_proxy_value_init (GValue *value)
|
||||||
{
|
{
|
||||||
@ -317,13 +337,7 @@ static void
|
|||||||
boxed_proxy_value_free (GValue *value)
|
boxed_proxy_value_free (GValue *value)
|
||||||
{
|
{
|
||||||
if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
|
if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
|
||||||
{
|
_g_type_boxed_free (G_VALUE_TYPE (value), value->data[0].v_pointer);
|
||||||
BoxedNode key, *node;
|
|
||||||
|
|
||||||
key.type = G_VALUE_TYPE (value);
|
|
||||||
node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
|
|
||||||
node->free (value->data[0].v_pointer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -331,13 +345,7 @@ boxed_proxy_value_copy (const GValue *src_value,
|
|||||||
GValue *dest_value)
|
GValue *dest_value)
|
||||||
{
|
{
|
||||||
if (src_value->data[0].v_pointer)
|
if (src_value->data[0].v_pointer)
|
||||||
{
|
dest_value->data[0].v_pointer = _g_type_boxed_copy (G_VALUE_TYPE (src_value), src_value->data[0].v_pointer);
|
||||||
BoxedNode key, *node;
|
|
||||||
|
|
||||||
key.type = G_VALUE_TYPE (src_value);
|
|
||||||
node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
|
|
||||||
dest_value->data[0].v_pointer = node->copy (src_value->data[0].v_pointer);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
dest_value->data[0].v_pointer = src_value->data[0].v_pointer;
|
dest_value->data[0].v_pointer = src_value->data[0].v_pointer;
|
||||||
}
|
}
|
||||||
@ -354,11 +362,6 @@ boxed_proxy_collect_value (GValue *value,
|
|||||||
GTypeCValue *collect_values,
|
GTypeCValue *collect_values,
|
||||||
guint collect_flags)
|
guint collect_flags)
|
||||||
{
|
{
|
||||||
BoxedNode key, *node;
|
|
||||||
|
|
||||||
key.type = G_VALUE_TYPE (value);
|
|
||||||
node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
|
|
||||||
|
|
||||||
if (!collect_values[0].v_pointer)
|
if (!collect_values[0].v_pointer)
|
||||||
value->data[0].v_pointer = NULL;
|
value->data[0].v_pointer = NULL;
|
||||||
else
|
else
|
||||||
@ -369,7 +372,7 @@ boxed_proxy_collect_value (GValue *value,
|
|||||||
value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
|
value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
value->data[0].v_pointer = node->copy (collect_values[0].v_pointer);
|
value->data[0].v_pointer = _g_type_boxed_copy (G_VALUE_TYPE (value), collect_values[0].v_pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -391,13 +394,7 @@ boxed_proxy_lcopy_value (const GValue *value,
|
|||||||
else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
|
else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
|
||||||
*boxed_p = value->data[0].v_pointer;
|
*boxed_p = value->data[0].v_pointer;
|
||||||
else
|
else
|
||||||
{
|
*boxed_p = _g_type_boxed_copy (G_VALUE_TYPE (value), value->data[0].v_pointer);
|
||||||
BoxedNode key, *node;
|
|
||||||
|
|
||||||
key.type = G_VALUE_TYPE (value);
|
|
||||||
node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
|
|
||||||
*boxed_p = node->copy (value->data[0].v_pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -490,13 +487,7 @@ g_boxed_copy (GType boxed_type,
|
|||||||
|
|
||||||
/* check if our proxying implementation is used, we can short-cut here */
|
/* check if our proxying implementation is used, we can short-cut here */
|
||||||
if (value_table->value_copy == boxed_proxy_value_copy)
|
if (value_table->value_copy == boxed_proxy_value_copy)
|
||||||
{
|
dest_boxed = _g_type_boxed_copy (boxed_type, src_boxed);
|
||||||
BoxedNode key, *node;
|
|
||||||
|
|
||||||
key.type = boxed_type;
|
|
||||||
node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
|
|
||||||
dest_boxed = node->copy ((gpointer) src_boxed);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GValue src_value, dest_value;
|
GValue src_value, dest_value;
|
||||||
@ -554,13 +545,7 @@ g_boxed_free (GType boxed_type,
|
|||||||
|
|
||||||
/* check if our proxying implementation is used, we can short-cut here */
|
/* check if our proxying implementation is used, we can short-cut here */
|
||||||
if (value_table->value_free == boxed_proxy_value_free)
|
if (value_table->value_free == boxed_proxy_value_free)
|
||||||
{
|
_g_type_boxed_free (boxed_type, boxed);
|
||||||
BoxedNode key, *node;
|
|
||||||
|
|
||||||
key.type = boxed_type;
|
|
||||||
node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
|
|
||||||
node->free (boxed);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GValue value;
|
GValue value;
|
||||||
@ -611,13 +596,10 @@ g_value_dup_boxed (const GValue *value)
|
|||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
value_set_boxed_internal (GValue *value,
|
value_set_boxed_internal (GValue *value,
|
||||||
gconstpointer const_boxed,
|
gconstpointer boxed,
|
||||||
gboolean need_copy,
|
gboolean need_copy,
|
||||||
gboolean need_free)
|
gboolean need_free)
|
||||||
{
|
{
|
||||||
BoxedNode key, *node;
|
|
||||||
gpointer boxed = (gpointer) const_boxed;
|
|
||||||
|
|
||||||
if (!boxed)
|
if (!boxed)
|
||||||
{
|
{
|
||||||
/* just resetting to NULL might not be desired, need to
|
/* just resetting to NULL might not be desired, need to
|
||||||
@ -629,27 +611,10 @@ value_set_boxed_internal (GValue *value,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
key.type = G_VALUE_TYPE (value);
|
if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
|
||||||
node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
|
g_boxed_free (G_VALUE_TYPE (value), value->data[0].v_pointer);
|
||||||
|
value->data[1].v_uint = need_free ? 0 : G_VALUE_NOCOPY_CONTENTS;
|
||||||
if (node)
|
value->data[0].v_pointer = need_copy ? g_boxed_copy (G_VALUE_TYPE (value), boxed) : (gconstpointer) boxed;
|
||||||
{
|
|
||||||
/* we proxy this type, free contents and copy right away */
|
|
||||||
if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
|
|
||||||
node->free (value->data[0].v_pointer);
|
|
||||||
value->data[1].v_uint = need_free ? 0 : G_VALUE_NOCOPY_CONTENTS;
|
|
||||||
value->data[0].v_pointer = need_copy ? node->copy (boxed) : boxed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* we don't handle this type, free contents and let g_boxed_copy()
|
|
||||||
* figure what's required
|
|
||||||
*/
|
|
||||||
if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
|
|
||||||
g_boxed_free (G_VALUE_TYPE (value), value->data[0].v_pointer);
|
|
||||||
value->data[1].v_uint = need_free ? 0 : G_VALUE_NOCOPY_CONTENTS;
|
|
||||||
value->data[0].v_pointer = need_copy ? g_boxed_copy (G_VALUE_TYPE (value), boxed) : boxed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user