Optimize gtk_css_node_declaration_has_class

This function is getting called a lot. Statistics for the gtk3-demo
listbox example show most calls with 0-4 classes. Unrolling the cases
a bit brings the instruction count in callgrind from 93M to 52M.
This commit is contained in:
Matthias Clasen 2015-09-09 14:40:36 -04:00
parent 59797754b4
commit cf0e087527

View File

@ -311,7 +311,28 @@ gboolean
gtk_css_node_declaration_has_class (const GtkCssNodeDeclaration *decl,
GQuark class_quark)
{
return find_class (decl, class_quark, NULL);
GQuark *classes = get_classes (decl);
switch (decl->n_classes)
{
case 3:
if (classes[2] == class_quark)
return TRUE;
case 2:
if (classes[1] == class_quark)
return TRUE;
case 1:
if (classes[0] == class_quark)
return TRUE;
case 0:
return FALSE;
default:
return find_class (decl, class_quark, NULL);
}
}
GList *