Replace uses of GBSearchArray with GArray and bsearch(), to remove

Sat Sep  8 13:53:09 2001  Owen Taylor  <otaylor@redhat.com>

	* gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
	with GArray and bsearch(), to remove dependency on a still
	evolving interface that we want to keep private to glib/gobject.
This commit is contained in:
Owen Taylor 2001-09-08 17:55:02 +00:00 committed by Owen Taylor
parent 372853b107
commit fd97e93165
11 changed files with 160 additions and 125 deletions

View File

@ -1,3 +1,9 @@
Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
with GArray and bsearch(), to remove dependency on a still
evolving interface that we want to keep private to glib/gobject.
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):

View File

@ -1,3 +1,9 @@
Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
with GArray and bsearch(), to remove dependency on a still
evolving interface that we want to keep private to glib/gobject.
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):

View File

@ -1,3 +1,9 @@
Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
with GArray and bsearch(), to remove dependency on a still
evolving interface that we want to keep private to glib/gobject.
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):

View File

@ -1,3 +1,9 @@
Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
with GArray and bsearch(), to remove dependency on a still
evolving interface that we want to keep private to glib/gobject.
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):

View File

@ -1,3 +1,9 @@
Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
with GArray and bsearch(), to remove dependency on a still
evolving interface that we want to keep private to glib/gobject.
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):

View File

@ -1,3 +1,9 @@
Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
with GArray and bsearch(), to remove dependency on a still
evolving interface that we want to keep private to glib/gobject.
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):

View File

@ -1,3 +1,9 @@
Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
with GArray and bsearch(), to remove dependency on a still
evolving interface that we want to keep private to glib/gobject.
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):

View File

@ -1070,14 +1070,14 @@ gtk_rc_style_finalize (GObject *object)
{
guint i;
for (i = 0; i < rc_style->rc_properties->n_nodes; i++)
for (i = 0; i < rc_style->rc_properties->len; i++)
{
GtkRcProperty *node = g_bsearch_array_get_nth (rc_style->rc_properties, i);
GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
g_free (node->origin);
g_value_unset (&node->value);
}
g_bsearch_array_destroy (rc_style->rc_properties);
g_array_free (rc_style->rc_properties, TRUE);
rc_style->rc_properties = NULL;
}
@ -1154,13 +1154,63 @@ gtk_rc_properties_cmp (gconstpointer bsearch_node1,
{
const GtkRcProperty *prop1 = bsearch_node1;
const GtkRcProperty *prop2 = bsearch_node2;
gint cmp;
cmp = G_BSEARCH_ARRAY_CMP (prop1->type_name, prop2->type_name);
if (cmp == 0)
cmp = G_BSEARCH_ARRAY_CMP (prop1->property_name, prop2->property_name);
if (prop1->type_name == prop2->type_name)
return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
else
return prop1->type_name < prop2->type_name ? -1 : 1;
}
return cmp;
static void
insert_rc_property (GtkRcStyle *style,
GtkRcProperty *property,
gboolean replace)
{
guint i;
GtkRcProperty *new_property = NULL;
GtkRcProperty key = { 0, 0, NULL, { 0, }, };
key.type_name = property->type_name;
key.property_name = property->property_name;
if (!style->rc_properties)
style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
i = 0;
while (i < style->rc_properties->len)
{
gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
if (cmp == 0)
{
if (replace)
{
new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
g_free (new_property->origin);
g_value_unset (&new_property->value);
*new_property = key;
break;
}
else
return;
}
else if (cmp > 0)
break;
i++;
}
if (!new_property)
{
g_array_insert_val (style->rc_properties, i, key);
new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
}
new_property->origin = g_strdup (property->origin);
g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
g_value_copy (&property->value, &new_property->value);
}
static void
@ -1212,25 +1262,10 @@ gtk_rc_style_real_merge (GtkRcStyle *dest,
{
guint i;
if (!dest->rc_properties)
dest->rc_properties = g_bsearch_array_new (sizeof (GtkRcProperty),
gtk_rc_properties_cmp,
0);
for (i = 0; i < src->rc_properties->n_nodes; i++)
{
GtkRcProperty *node = g_bsearch_array_get_nth (src->rc_properties, i);
GtkRcProperty *prop, key = { 0, 0, NULL, { 0, }, };
key.type_name = node->type_name;
key.property_name = node->property_name;
prop = g_bsearch_array_insert (dest->rc_properties, &key, FALSE);
if (!prop->origin)
{
prop->origin = g_strdup (node->origin);
g_value_init (&prop->value, G_VALUE_TYPE (&node->value));
g_value_copy (&node->value, &prop->value);
}
}
for (i = 0; i < src->rc_properties->len; i++)
insert_rc_property (dest,
&g_array_index (src->rc_properties, GtkRcProperty, i),
FALSE);
}
}
@ -2317,27 +2352,10 @@ gtk_rc_parse_style (GtkRcContext *context,
{
guint i;
if (!rc_style->rc_properties)
rc_style->rc_properties = g_bsearch_array_new (sizeof (GtkRcProperty),
gtk_rc_properties_cmp,
0);
for (i = 0; i < parent_style->rc_properties->n_nodes; i++)
{
GtkRcProperty *node = g_bsearch_array_get_nth (parent_style->rc_properties, i);
GtkRcProperty *prop, key = { 0, 0, NULL, { 0, }, };
key.type_name = node->type_name;
key.property_name = node->property_name;
prop = g_bsearch_array_insert (rc_style->rc_properties, &key, FALSE);
if (prop->origin)
{
g_free (prop->origin);
g_value_unset (&prop->value);
}
prop->origin = g_strdup (node->origin);
g_value_init (&prop->value, G_VALUE_TYPE (&node->value));
g_value_copy (&node->value, &prop->value);
}
for (i = 0; i < parent_style->rc_properties->len; i++)
insert_rc_property (rc_style,
&g_array_index (parent_style->rc_properties, GtkRcProperty, i),
TRUE);
}
for (i = 0; i < 5; i++)
@ -2463,29 +2481,13 @@ gtk_rc_parse_style (GtkRcContext *context,
token = gtk_rc_parse_assignment (scanner, &prop);
if (token == G_TOKEN_NONE)
{
GtkRcProperty *tmp;
g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
insert_rc_property (rc_style, &prop, TRUE);
}
if (!rc_style->rc_properties)
rc_style->rc_properties = g_bsearch_array_new (sizeof (GtkRcProperty),
gtk_rc_properties_cmp,
0);
tmp = g_bsearch_array_insert (rc_style->rc_properties, &prop, FALSE);
if (prop.origin != tmp->origin)
{
g_free (tmp->origin);
g_value_unset (&tmp->value);
tmp->origin = prop.origin;
memcpy (&tmp->value, &prop.value, sizeof (prop.value));
}
}
else
{
g_free (prop.origin);
if (G_VALUE_TYPE (&prop.value))
g_value_unset (&prop.value);
}
g_free (prop.origin);
if (G_VALUE_TYPE (&prop.value))
g_value_unset (&prop.value);
}
else
{
@ -2554,7 +2556,9 @@ _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
key.type_name = type_name;
key.property_name = property_name;
node = g_bsearch_array_lookup (rc_style->rc_properties, &key);
node = bsearch (&key,
rc_style->rc_properties->data, rc_style->rc_properties->len,
sizeof (GtkRcProperty), gtk_rc_properties_cmp);
}
return node;

View File

@ -76,7 +76,7 @@ struct _GtkRcStyle
gint ythickness;
/*< private >*/
GBSearchArray *rc_properties;
GArray *rc_properties;
/* list of RC style lists including this RC style */
GSList *rc_style_lists;

View File

@ -25,6 +25,7 @@
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "gtkgc.h"
#include "gtkrc.h"
@ -562,6 +563,25 @@ gtk_style_class_init (GtkStyleClass *klass)
klass->draw_resize_grip = gtk_default_draw_resize_grip;
}
static void
clear_property_cache (GtkStyle *style)
{
if (style->property_cache)
{
guint i;
for (i = 0; i < style->property_cache->len; i++)
{
PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
g_param_spec_unref (node->pspec);
g_value_unset (&node->value);
}
g_array_free (style->property_cache, TRUE);
style->property_cache = NULL;
}
}
static void
gtk_style_finalize (GObject *object)
{
@ -569,20 +589,7 @@ gtk_style_finalize (GObject *object)
g_return_if_fail (style->attach_count == 0);
if (style->property_cache)
{
guint i;
for (i = 0; i < style->property_cache->n_nodes; i++)
{
PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
g_param_spec_unref (node->pspec);
g_value_unset (&node->value);
}
g_bsearch_array_destroy (style->property_cache);
style->property_cache = NULL;
}
clear_property_cache (style);
if (style->styles)
{
@ -1206,20 +1213,7 @@ gtk_style_real_copy (GtkStyle *style,
gtk_rc_style_ref (src->rc_style);
/* don't copy, just clear cache */
if (style->property_cache)
{
guint i;
for (i = 0; i < style->property_cache->n_nodes; i++)
{
PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
g_param_spec_unref (node->pspec);
g_value_unset (&node->value);
}
g_bsearch_array_destroy (style->property_cache);
style->property_cache = NULL;
}
clear_property_cache (style);
}
static void
@ -1230,20 +1224,7 @@ gtk_style_real_init_from_rc (GtkStyle *style,
gint i;
/* cache _should_ be still empty */
if (style->property_cache)
{
guint i;
for (i = 0; i < style->property_cache->n_nodes; i++)
{
PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
g_param_spec_unref (node->pspec);
g_value_unset (&node->value);
}
g_bsearch_array_destroy (style->property_cache);
style->property_cache = NULL;
}
clear_property_cache (style);
if (rc_style->font_desc)
{
@ -1297,13 +1278,11 @@ style_property_values_cmp (gconstpointer bsearch_node1,
{
const PropertyValue *val1 = bsearch_node1;
const PropertyValue *val2 = bsearch_node2;
gint cmp;
cmp = G_BSEARCH_ARRAY_CMP (val1->widget_type, val2->widget_type);
if (cmp == 0)
cmp = G_BSEARCH_ARRAY_CMP (val1->pspec, val2->pspec);
return cmp;
if (val1->widget_type == val2->widget_type)
return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
else
return val1->widget_type < val2->widget_type ? -1 : 1;
}
const GValue*
@ -1314,6 +1293,7 @@ _gtk_style_peek_property_value (GtkStyle *style,
{
PropertyValue *pcache, key = { 0, NULL, { 0, } };
const GtkRcProperty *rcprop = NULL;
guint i;
g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
@ -1322,16 +1302,25 @@ _gtk_style_peek_property_value (GtkStyle *style,
/* need value cache array */
if (!style->property_cache)
style->property_cache = g_bsearch_array_new (sizeof (PropertyValue),
style_property_values_cmp,
0);
style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
/* lookup, or insert value if not yet present */
key.widget_type = widget_type;
key.pspec = pspec;
pcache = g_bsearch_array_insert (style->property_cache, &key, FALSE);
if (G_VALUE_TYPE (&pcache->value))
pcache = bsearch (&key,
style->property_cache->data, style->property_cache->len,
sizeof (PropertyValue), style_property_values_cmp);
if (pcache)
return &pcache->value;
i = 0;
while (i < style->property_cache->len &&
style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
i++;
g_array_insert_val (style->property_cache, i, key);
pcache = &g_array_index (style->property_cache, PropertyValue, i);
/* cache miss, initialize value type, then set contents */
g_param_spec_ref (pcache->pspec);
g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));

View File

@ -117,7 +117,7 @@ struct _GtkStyle
GtkRcStyle *rc_style;
GSList *styles; /* of type GtkStyle* */
GBSearchArray *property_cache;
GArray *property_cache;
GSList *icon_factories; /* of type GtkIconFactory* */
};