[gtk/wip/baedert/css-values: 4/7] cssarrayvalue: Loosen the definition of "array value"
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/css-values: 4/7] cssarrayvalue: Loosen the definition of "array value"
- Date: Thu, 9 Jan 2020 11:22:20 +0000 (UTC)
commit ce17b8ae79ef22a0e1a918b73322a3fe82b52f48
Author: Timm Bäder <tbaeder redhat com>
Date: Wed Jan 8 08:37:04 2020 +0100
cssarrayvalue: Loosen the definition of "array value"
Just allow calling _get_nth() and _get_n_values() on every kind of css
value. This way we can allow all values in places where only array
values would be allowed before.
This spares us around 1000 array values in the widget factory.
css value stats before:
GtkCssFilterValue: 3
GtkCssRgbaValue: 1092
GtkCssShadowValue: 708
GtkCssEaseValue: 33
GtkCssBorderValue: 2
GtkCssTransformValue: 11
GtkCssDimensionValue: 882
GtkCssShadowsValue: 584
GtkCssBgSizeValue: 23
GtkCssIdentValue: 25
GtkCssPositionValue: 81
GtkCssCornerValue: 556
GtkCssArrayValue: 1130
GtkCssStringValue: 33
GtkCssPaletteValue: 29
GtkCssImageValue: 2765
GtkCssColorValue: 1452
SUM: 9415
and after:
GtkCssBgSizeValue: 23
GtkCssIdentValue: 25
GtkCssPositionValue: 81
GtkCssCornerValue: 556
GtkCssArrayValue: 143
GtkCssStringValue: 33
GtkCssPaletteValue: 29
GtkCssImageValue: 2765
GtkCssColorValue: 1452
GtkCssFilterValue: 3
GtkCssRgbaValue: 1092
GtkCssShadowValue: 708
GtkCssEaseValue: 33
GtkCssBorderValue: 2
GtkCssTransformValue: 11
GtkCssDimensionValue: 882
GtkCssShadowsValue: 584
SUM: 8428
9415 to 8428 is a 987 reduction (10.4%)
gtk/gtkcssarrayvalue.c | 13 +++++++++++--
gtk/gtkcssarrayvalueprivate.h | 2 +-
gtk/gtkcssstylepropertyimpl.c | 20 ++++++++++----------
gtk/gtkcssstylepropertyprivate.h | 2 +-
4 files changed, 23 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtkcssarrayvalue.c b/gtk/gtkcssarrayvalue.c
index 25bfbe47de..60019fea5c 100644
--- a/gtk/gtkcssarrayvalue.c
+++ b/gtk/gtkcssarrayvalue.c
@@ -395,6 +395,9 @@ _gtk_css_array_value_new_from_array (GtkCssValue **values,
g_return_val_if_fail (values != NULL, NULL);
g_return_val_if_fail (n_values > 0, NULL);
+
+ if (n_values == 1)
+ return values[0];
result = _gtk_css_value_alloc (>K_CSS_VALUE_ARRAY, sizeof (GtkCssValue) + sizeof (GtkCssValue *) *
(n_values - 1));
result->n_values = n_values;
@@ -431,9 +434,12 @@ _gtk_css_array_value_parse (GtkCssParser *parser,
}
GtkCssValue *
-_gtk_css_array_value_get_nth (const GtkCssValue *value,
- guint i)
+_gtk_css_array_value_get_nth (GtkCssValue *value,
+ guint i)
{
+ if (value->class != >K_CSS_VALUE_ARRAY)
+ return value;
+
g_return_val_if_fail (value != NULL, NULL);
g_return_val_if_fail (value->class == >K_CSS_VALUE_ARRAY, NULL);
g_return_val_if_fail (value->n_values > 0, NULL);
@@ -444,6 +450,9 @@ _gtk_css_array_value_get_nth (const GtkCssValue *value,
guint
_gtk_css_array_value_get_n_values (const GtkCssValue *value)
{
+ if (value->class != >K_CSS_VALUE_ARRAY)
+ return 1;
+
g_return_val_if_fail (value != NULL, 0);
g_return_val_if_fail (value->class == >K_CSS_VALUE_ARRAY, 0);
diff --git a/gtk/gtkcssarrayvalueprivate.h b/gtk/gtkcssarrayvalueprivate.h
index 23fb5c4697..0ff1295f48 100644
--- a/gtk/gtkcssarrayvalueprivate.h
+++ b/gtk/gtkcssarrayvalueprivate.h
@@ -32,7 +32,7 @@ GtkCssValue * _gtk_css_array_value_new_from_array (GtkCssValue **
GtkCssValue * _gtk_css_array_value_parse (GtkCssParser *parser,
GtkCssValue * (* parse_func) (GtkCssParser
*));
-GtkCssValue * _gtk_css_array_value_get_nth (const GtkCssValue *value,
+GtkCssValue * _gtk_css_array_value_get_nth (GtkCssValue *value,
guint i);
guint _gtk_css_array_value_get_n_values (const GtkCssValue *value);
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 0ebaffeaf7..5a36b933cb 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -105,7 +105,7 @@ gtk_css_style_property_register (const char * name,
static void
query_length_as_int (GtkCssStyleProperty *property,
- const GtkCssValue *css_value,
+ GtkCssValue *css_value,
GValue *value)
{
g_value_init (value, G_TYPE_INT);
@@ -114,7 +114,7 @@ query_length_as_int (GtkCssStyleProperty *property,
static void
query_font_size (GtkCssStyleProperty *property,
- const GtkCssValue *css_value,
+ GtkCssValue *css_value,
GValue *value)
{
g_value_init (value, G_TYPE_DOUBLE);
@@ -123,7 +123,7 @@ query_font_size (GtkCssStyleProperty *property,
static void
query_border (GtkCssStyleProperty *property,
- const GtkCssValue *css_value,
+ GtkCssValue *css_value,
GValue *value)
{
GtkBorder border;
@@ -147,7 +147,7 @@ color_parse (GtkCssStyleProperty *property,
static void
color_query (GtkCssStyleProperty *property,
- const GtkCssValue *css_value,
+ GtkCssValue *css_value,
GValue *value)
{
g_value_init (value, GDK_TYPE_RGBA);
@@ -200,7 +200,7 @@ font_family_parse (GtkCssStyleProperty *property,
static void
font_family_query (GtkCssStyleProperty *property,
- const GtkCssValue *css_value,
+ GtkCssValue *css_value,
GValue *value)
{
GPtrArray *array;
@@ -234,7 +234,7 @@ font_style_parse (GtkCssStyleProperty *property,
static void
font_style_query (GtkCssStyleProperty *property,
- const GtkCssValue *css_value,
+ GtkCssValue *css_value,
GValue *value)
{
g_value_init (value, PANGO_TYPE_STYLE);
@@ -267,7 +267,7 @@ font_weight_parse (GtkCssStyleProperty *property,
static void
font_weight_query (GtkCssStyleProperty *property,
- const GtkCssValue *css_value,
+ GtkCssValue *css_value,
GValue *value)
{
g_value_init (value, PANGO_TYPE_WEIGHT);
@@ -288,7 +288,7 @@ font_stretch_parse (GtkCssStyleProperty *property,
static void
font_stretch_query (GtkCssStyleProperty *property,
- const GtkCssValue *css_value,
+ GtkCssValue *css_value,
GValue *value)
{
g_value_init (value, PANGO_TYPE_STRETCH);
@@ -309,7 +309,7 @@ parse_border_style (GtkCssStyleProperty *property,
static void
query_border_style (GtkCssStyleProperty *property,
- const GtkCssValue *css_value,
+ GtkCssValue *css_value,
GValue *value)
{
g_value_init (value, GTK_TYPE_BORDER_STYLE);
@@ -361,7 +361,7 @@ opacity_parse (GtkCssStyleProperty *property,
static void
opacity_query (GtkCssStyleProperty *property,
- const GtkCssValue *css_value,
+ GtkCssValue *css_value,
GValue *value)
{
g_value_init (value, G_TYPE_DOUBLE);
diff --git a/gtk/gtkcssstylepropertyprivate.h b/gtk/gtkcssstylepropertyprivate.h
index 1403dee181..b7c073b299 100644
--- a/gtk/gtkcssstylepropertyprivate.h
+++ b/gtk/gtkcssstylepropertyprivate.h
@@ -37,7 +37,7 @@ typedef struct _GtkCssStylePropertyClass GtkCssStylePropertyClass;
typedef GtkCssValue * (* GtkCssStylePropertyParseFunc) (GtkCssStyleProperty *property,
GtkCssParser *parser);
typedef void (* GtkCssStylePropertyQueryFunc) (GtkCssStyleProperty *property,
- const GtkCssValue *cssvalue,
+ GtkCssValue *cssvalue,
GValue *value);
struct _GtkCssStyleProperty
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]