cssarrayvalue: Allow calling array API on non-arrays

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%)
This commit is contained in:
Timm Bäder 2020-01-08 08:37:04 +01:00
parent 1200fe2daf
commit 8d15efba8f
4 changed files with 23 additions and 14 deletions

View File

@ -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 (&GTK_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 != &GTK_CSS_VALUE_ARRAY)
return value;
g_return_val_if_fail (value != NULL, NULL);
g_return_val_if_fail (value->class == &GTK_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 != &GTK_CSS_VALUE_ARRAY)
return 1;
g_return_val_if_fail (value != NULL, 0);
g_return_val_if_fail (value->class == &GTK_CSS_VALUE_ARRAY, 0);

View File

@ -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);

View File

@ -104,7 +104,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);
@ -113,7 +113,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);
@ -122,7 +122,7 @@ query_font_size (GtkCssStyleProperty *property,
static void
query_border (GtkCssStyleProperty *property,
const GtkCssValue *css_value,
GtkCssValue *css_value,
GValue *value)
{
GtkBorder border;
@ -146,7 +146,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);
@ -199,7 +199,7 @@ font_family_parse (GtkCssStyleProperty *property,
static void
font_family_query (GtkCssStyleProperty *property,
const GtkCssValue *css_value,
GtkCssValue *css_value,
GValue *value)
{
GPtrArray *array;
@ -233,7 +233,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);
@ -266,7 +266,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);
@ -287,7 +287,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);
@ -308,7 +308,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);
@ -360,7 +360,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);

View File

@ -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
{