css: Avoid allocations in gtk_css_value_array_compute

Almost all array computations lead to no changes (99% in nautilus)
so we avoid the upfront allocation and delay it until we know its
needed. This drops the allocate/free from the profile.
This commit is contained in:
Alexander Larsson 2012-12-03 14:30:37 +01:00
parent 7ec33e63c0
commit c3e9112f7f

View File

@ -51,28 +51,33 @@ gtk_css_value_array_compute (GtkCssValue *value,
GtkCssDependencies *dependencies) GtkCssDependencies *dependencies)
{ {
GtkCssValue *result; GtkCssValue *result;
gboolean changed = FALSE; GtkCssValue *i_value;
guint i; guint i, j;
GtkCssDependencies child_deps; GtkCssDependencies child_deps;
if (value->n_values == 0) result = NULL;
return _gtk_css_value_ref (value);
result = _gtk_css_array_value_new_from_array (value->values, value->n_values);
for (i = 0; i < value->n_values; i++) for (i = 0; i < value->n_values; i++)
{ {
result->values[i] = _gtk_css_value_compute (value->values[i], property_id, provider, values, parent_values, &child_deps); i_value = _gtk_css_value_compute (value->values[i], property_id, provider, values, parent_values, &child_deps);
*dependencies = _gtk_css_dependencies_union (*dependencies, child_deps); *dependencies = _gtk_css_dependencies_union (*dependencies, child_deps);
changed |= (result->values[i] != value->values[i]); if (result == NULL &&
i_value != value->values[i])
{
result = _gtk_css_array_value_new_from_array (value->values, value->n_values);
for (j = 0; j < i; j++)
_gtk_css_value_ref (result->values[j]);
}
if (result != NULL)
result->values[i] = i_value;
else
_gtk_css_value_unref (i_value);
} }
if (!changed) if (result == NULL)
{ return _gtk_css_value_ref (value);
_gtk_css_value_unref (result);
return _gtk_css_value_ref (value);
}
return result; return result;
} }