cssshadowsvalue: Avoid allocating new value if not needed

This commit is contained in:
Benjamin Otte 2016-04-21 22:28:58 +02:00
parent f93eca5604
commit c081ca2d4c
2 changed files with 41 additions and 5 deletions

View File

@ -57,19 +57,40 @@ gtk_css_value_shadows_compute (GtkCssValue *value,
GtkCssStyle *style,
GtkCssStyle *parent_style)
{
GtkCssValue *result;
guint i;
GtkCssValue *result, *tmp;
guint i, j;
if (value->len == 0)
return _gtk_css_value_ref (value);
result = gtk_css_shadows_value_new (value->values, value->len);
result = NULL;
for (i = 0; i < value->len; i++)
{
result->values[i] = _gtk_css_value_compute (value->values[i], property_id, provider, style, parent_style);
tmp = _gtk_css_value_compute (value->values[i], property_id, provider, style, parent_style);
if (result)
{
result->values[i] = tmp;
}
else if (tmp != value->values[i])
{
result = gtk_css_shadows_value_new (value->values, value->len);
for (j = 0; j < i; j++)
{
_gtk_css_value_ref (result->values[j]);
}
result->values[i] = tmp;
}
else
{
_gtk_css_value_unref (tmp);
}
}
return result;
if (result != NULL)
return result;
else
return _gtk_css_value_ref (value);
}
static gboolean

View File

@ -77,6 +77,21 @@ gtk_css_value_shadow_compute (GtkCssValue *shadow,
spread = _gtk_css_value_compute (shadow->spread, property_id, provider, style, parent_style),
color = _gtk_css_value_compute (shadow->color, property_id, provider, style, parent_style);
if (hoffset == shadow->hoffset &&
voffset == shadow->voffset &&
radius == shadow->radius &&
spread == shadow->spread &&
color == shadow->color)
{
_gtk_css_value_unref (hoffset);
_gtk_css_value_unref (voffset);
_gtk_css_value_unref (radius);
_gtk_css_value_unref (spread);
_gtk_css_value_unref (color);
return _gtk_css_value_ref (shadow);
}
return gtk_css_shadow_value_new (hoffset, voffset, radius, spread, shadow->inset, color);
}