Commit c081ca2d authored by Benjamin Otte's avatar Benjamin Otte

cssshadowsvalue: Avoid allocating new value if not needed

parent f93eca56
......@@ -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
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment