static guint
gtk_css_selector_hash_one (const GtkCssSelector *selector)
{
- return GPOINTER_TO_UINT (selector->class) ^ selector->class->hash_one (selector);
+ return selector->class->hash_one (selector);
}
static inline gpointer *
static guint
gtk_css_selector_default_hash_one (const GtkCssSelector *selector)
{
- return 0;
+ return GPOINTER_TO_UINT (selector->class);
}
static int
static guint
hash_name (const GtkCssSelector *a)
{
- return a->name.name;
+ return gtk_css_hash_name (a->name.name);
}
static int
static guint
hash_class (const GtkCssSelector *a)
{
- return a->style_class.style_class;
+ return gtk_css_hash_class (a->style_class.style_class);
}
static int
static guint
hash_id (const GtkCssSelector *a)
{
- return a->id.name;
+ return gtk_css_hash_id (a->id.name);
}
static int
const char * gtk_css_pseudoclass_name (GtkStateFlags flags);
+/* These hash functions are selected so they achieve 2 things:
+ * 1. collision free among each other
+ * Hashing the CSS selectors "button", ".button" and "#button" should give different results.
+ * So we multiply the hash values with distinct prime numbers.
+ * 2. generate small numbers
+ * It's why the code uses quarks instead of interned strings. Interned strings are random
+ * pointers, quarks are numbers increasing from 0.
+ * Both of these goals should achieve a bloom filter for selector matching that is as free
+ * of collisions as possible.
+ */
+static inline guint
+gtk_css_hash_class (GQuark klass)
+{
+ return klass * 5;
+}
+static inline guint
+gtk_css_hash_name (GQuark name)
+{
+ return name * 7;
+}
+static inline guint
+gtk_css_hash_id (GQuark id)
+{
+ return id * 11;
+}
G_END_DECLS