static void
gtk_css_value_corner_print (const GtkCssValue *corner,
- GString *string)
+ GString *string)
{
_gtk_css_value_print (corner->x, string);
if (!_gtk_css_value_equal (corner->x, corner->y))
gtk_css_value_corner_print
};
+static GtkCssValue corner_singletons[] = {
+ { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL },
+ { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL },
+ { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL },
+ { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL },
+ { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL },
+ { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL },
+ { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL },
+ { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL },
+};
+
+static inline void
+initialize_corner_singletons (void)
+{
+ static gboolean initialized = FALSE;
+
+ if (initialized)
+ return;
+
+ for (unsigned int i = 0; i < G_N_ELEMENTS (corner_singletons); i++)
+ {
+ corner_singletons[i].x = gtk_css_dimension_value_new (i, GTK_CSS_PX);
+ corner_singletons[i].y = gtk_css_value_ref (corner_singletons[i].x);
+ }
+
+ initialized = TRUE;
+}
+
GtkCssValue *
_gtk_css_corner_value_new (GtkCssValue *x,
GtkCssValue *y)
{
GtkCssValue *result;
+ if (x == y &&
+ gtk_css_number_value_get_dimension (x) == GTK_CSS_DIMENSION_LENGTH)
+ {
+ initialize_corner_singletons ();
+
+ for (unsigned int i = 0; i < G_N_ELEMENTS (corner_singletons); i++)
+ {
+ if (corner_singletons[i].x == x)
+ {
+ gtk_css_value_unref (x);
+ gtk_css_value_unref (y);
+
+ return gtk_css_value_ref (&corner_singletons[i]);
+ }
+ }
+ }
+
result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_CORNER);
result->x = x;
result->y = y;