mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-17 07:30:09 +00:00
cssimagefallback: Avoid allocating GPtrArray for colors
If we just parse a color, like image(#FFF), avoid allocating the GPtrArray to store images. This happens in Adwaita for background images of backdrop buttons. We save around 70 GPtrArrays this way.
This commit is contained in:
parent
716b5afe6a
commit
484dcc043b
@ -209,6 +209,9 @@ gtk_css_image_fallback_parse_arg (GtkCssParser *parser,
|
|||||||
if (image == NULL)
|
if (image == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (!data->images)
|
||||||
|
data->images = g_ptr_array_new_with_free_func (g_object_unref);
|
||||||
|
|
||||||
g_ptr_array_add (data->images, image);
|
g_ptr_array_add (data->images, image);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -235,18 +238,25 @@ gtk_css_image_fallback_parse (GtkCssImage *image,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.images = g_ptr_array_new_with_free_func (g_object_unref);
|
|
||||||
|
|
||||||
if (!gtk_css_parser_consume_function (parser, 1, G_MAXUINT, gtk_css_image_fallback_parse_arg, &data))
|
if (!gtk_css_parser_consume_function (parser, 1, G_MAXUINT, gtk_css_image_fallback_parse_arg, &data))
|
||||||
{
|
{
|
||||||
g_clear_pointer (&data.color, _gtk_css_value_unref);
|
g_clear_pointer (&data.color, _gtk_css_value_unref);
|
||||||
g_ptr_array_free (data.images, TRUE);
|
if (data.images)
|
||||||
|
g_ptr_array_free (data.images, TRUE);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->color = data.color;
|
self->color = data.color;
|
||||||
self->n_images = data.images->len;
|
if (data.images)
|
||||||
self->images = (GtkCssImage **) g_ptr_array_free (data.images, FALSE);
|
{
|
||||||
|
self->n_images = data.images->len;
|
||||||
|
self->images = (GtkCssImage **) g_ptr_array_free (data.images, FALSE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self->n_images = 0;
|
||||||
|
self->images = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user