[gtk+] cssshadowsvalue: Don't heap-allocate shadows
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cssshadowsvalue: Don't heap-allocate shadows
- Date: Sun, 1 Oct 2017 07:18:17 +0000 (UTC)
commit 773973db78eba52e32d273a67387fd360fcdbb20
Author: Timm Bäder <mail baedert org>
Date: Sat Sep 30 13:11:51 2017 +0200
cssshadowsvalue: Don't heap-allocate shadows
This showed up in profiles in certain scenarios, so export a
_get_n_shadows getter instead and let callers provide a sufficiently
large allocated array of GskShadows, which we can use with
g_alloc/g_newa.
gtk/gtkcssshadowsvalue.c | 23 ++++++++++-------------
gtk/gtkcssshadowsvalueprivate.h | 6 ++++--
gtk/gtkrendericon.c | 34 ++++++++++++++++++----------------
gtk/gtksnapshot.c | 18 ++++++++++--------
4 files changed, 42 insertions(+), 39 deletions(-)
---
diff --git a/gtk/gtkcssshadowsvalue.c b/gtk/gtkcssshadowsvalue.c
index 40fb07a..bd687dc 100644
--- a/gtk/gtkcssshadowsvalue.c
+++ b/gtk/gtkcssshadowsvalue.c
@@ -268,23 +268,20 @@ _gtk_css_shadows_value_is_none (const GtkCssValue *shadows)
return shadows->len == 0;
}
-GskShadow *
-gtk_css_shadows_value_get_shadows (const GtkCssValue *shadows,
- gsize *n_shadows)
+gsize
+gtk_css_shadows_value_get_n_shadows (const GtkCssValue *shadows)
{
- GskShadow *result;
- guint i;
+ return shadows->len;
+}
- result = g_new (GskShadow, shadows->len);
+void
+gtk_css_shadows_value_get_shadows (const GtkCssValue *shadows,
+ GskShadow *out_shadows)
+{
+ guint i;
for (i = 0; i < shadows->len; i++)
- {
- gtk_css_shadow_value_get_shadow (shadows->values[i], &result[i]);
- }
-
- *n_shadows = shadows->len;
-
- return result;
+ gtk_css_shadow_value_get_shadow (shadows->values[i], &out_shadows[i]);
}
void
diff --git a/gtk/gtkcssshadowsvalueprivate.h b/gtk/gtkcssshadowsvalueprivate.h
index 039c8f0..be2f6b4 100644
--- a/gtk/gtkcssshadowsvalueprivate.h
+++ b/gtk/gtkcssshadowsvalueprivate.h
@@ -36,8 +36,10 @@ GtkCssValue * _gtk_css_shadows_value_parse (GtkCssParser
gboolean _gtk_css_shadows_value_is_none (const GtkCssValue *shadows);
-GskShadow * gtk_css_shadows_value_get_shadows (const GtkCssValue *shadows,
- gsize *n_shadows);
+gsize gtk_css_shadows_value_get_n_shadows (const GtkCssValue *shadows);
+
+void gtk_css_shadows_value_get_shadows (const GtkCssValue *shadows,
+ GskShadow *out_shadows);
void _gtk_css_shadows_value_paint_layout (const GtkCssValue *shadows,
cairo_t *cr,
diff --git a/gtk/gtkrendericon.c b/gtk/gtkrendericon.c
index 3ec7a3b..3cecd35 100644
--- a/gtk/gtkrendericon.c
+++ b/gtk/gtkrendericon.c
@@ -118,9 +118,13 @@ gtk_css_style_snapshot_icon (GtkCssStyle *style,
gtk_css_filter_value_push_snapshot (filter_value, snapshot);
- shadows = gtk_css_shadows_value_get_shadows (shadows_value, &n_shadows);
- if (shadows)
- gtk_snapshot_push_shadow (snapshot, shadows, n_shadows, "IconShadow<%zu>", n_shadows);
+ n_shadows = gtk_css_shadows_value_get_n_shadows (shadows_value);
+ if (n_shadows > 0)
+ {
+ shadows = g_newa (GskShadow, n_shadows);
+ gtk_css_shadows_value_get_shadows (shadows_value, shadows);
+ gtk_snapshot_push_shadow (snapshot, shadows, n_shadows, "IconShadow<%zu>", n_shadows);
+ }
if (graphene_matrix_is_identity (&transform_matrix))
{
@@ -143,11 +147,8 @@ gtk_css_style_snapshot_icon (GtkCssStyle *style,
gtk_snapshot_pop (snapshot);
}
- if (shadows)
- {
- gtk_snapshot_pop (snapshot);
- g_free (shadows);
- }
+ if (n_shadows > 0)
+ gtk_snapshot_pop (snapshot);
gtk_css_filter_value_pop_snapshot (filter_value, snapshot);
}
@@ -295,9 +296,13 @@ gtk_css_style_snapshot_icon_texture (GtkCssStyle *style,
gtk_css_filter_value_push_snapshot (filter_value, snapshot);
- shadows = gtk_css_shadows_value_get_shadows (shadows_value, &n_shadows);
- if (shadows)
- gtk_snapshot_push_shadow (snapshot, shadows, n_shadows, "IconShadow<%zu>", n_shadows);
+ n_shadows = gtk_css_shadows_value_get_n_shadows (shadows_value);
+ if (n_shadows > 0)
+ {
+ shadows = g_newa (GskShadow, n_shadows);
+ gtk_css_shadows_value_get_shadows (shadows_value, shadows);
+ gtk_snapshot_push_shadow (snapshot, shadows, n_shadows, "IconShadow<%zu>", n_shadows);
+ }
if (graphene_matrix_is_identity (&transform_matrix))
{
@@ -322,11 +327,8 @@ gtk_css_style_snapshot_icon_texture (GtkCssStyle *style,
gtk_snapshot_pop (snapshot);
}
- if (shadows)
- {
- gtk_snapshot_pop (snapshot);
- g_free (shadows);
- }
+ if (n_shadows > 0)
+ gtk_snapshot_pop (snapshot);
gtk_css_filter_value_pop_snapshot (filter_value, snapshot);
}
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index 7f5a1f1..293046b 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -1396,18 +1396,20 @@ gtk_snapshot_render_layout (GtkSnapshot *snapshot,
fg_color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context,
GTK_CSS_PROPERTY_COLOR));
shadows_value = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW);
- shadows = gtk_css_shadows_value_get_shadows (shadows_value, &n_shadows);
- if (shadows)
- gtk_snapshot_push_shadow (snapshot, shadows, n_shadows, "TextShadow<%zu>", n_shadows);
+ n_shadows = gtk_css_shadows_value_get_n_shadows (shadows_value);
- gsk_pango_show_layout (snapshot, fg_color, layout);
-
- if (shadows)
+ if (n_shadows > 0)
{
- gtk_snapshot_pop (snapshot);
- g_free (shadows);
+ shadows = g_newa (GskShadow, n_shadows);
+ gtk_css_shadows_value_get_shadows (shadows_value, shadows);
+ gtk_snapshot_push_shadow (snapshot, shadows, n_shadows, "TextShadow<%zu>", n_shadows);
}
+ gsk_pango_show_layout (snapshot, fg_color, layout);
+
+ if (n_shadows > 0)
+ gtk_snapshot_pop (snapshot);
+
gtk_snapshot_offset (snapshot, -x, -y);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]