mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 10:50:10 +00:00
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:
parent
1200fe2daf
commit
8d15efba8f
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user