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,8 +311,29 @@ gboolean
gtk_css_node_declaration_has_class (const GtkCssNodeDeclaration *decl,
GQuark class_quark)
{
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 *
gtk_css_node_declaration_list_classes (const GtkCssNodeDeclaration *decl)