[gtk+] cssshadowsvalue: Avoid allocating new value if not needed
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cssshadowsvalue: Avoid allocating new value if not needed
- Date: Thu, 21 Apr 2016 21:02:10 +0000 (UTC)
commit c081ca2d4c589fb77e097ad5ee2a9978bd91d2ed
Author: Benjamin Otte <otte redhat com>
Date: Thu Apr 21 22:28:58 2016 +0200
cssshadowsvalue: Avoid allocating new value if not needed
gtk/gtkcssshadowsvalue.c | 31 ++++++++++++++++++++++++++-----
gtk/gtkcssshadowvalue.c | 15 +++++++++++++++
2 files changed, 41 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkcssshadowsvalue.c b/gtk/gtkcssshadowsvalue.c
index 083b536..b58dde3 100644
--- a/gtk/gtkcssshadowsvalue.c
+++ b/gtk/gtkcssshadowsvalue.c
@@ -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
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index c06de2d..93b4dcf 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]