Commit d7dd6ecc authored by Matthias Clasen's avatar Matthias Clasen

Manipulate bits more efficiently

The function to translate GtkCssChange enum values to the PARENT
ones is called very frequently. This patch speeds it up tremendously.
The callgrind instruction count for this function in the listbox
demo goes from 108M to 7M.
parent a9481cb4
......@@ -70,28 +70,26 @@ _gtk_css_change_for_sibling (GtkCssChange match)
GtkCssChange
_gtk_css_change_for_child (GtkCssChange match)
{
static const GtkCssChangeTranslation table[] = {
{ GTK_CSS_CHANGE_CLASS, GTK_CSS_CHANGE_PARENT_CLASS },
{ GTK_CSS_CHANGE_NAME, GTK_CSS_CHANGE_PARENT_NAME },
{ GTK_CSS_CHANGE_ID, GTK_CSS_CHANGE_PARENT_ID },
{ GTK_CSS_CHANGE_FIRST_CHILD, GTK_CSS_CHANGE_PARENT_FIRST_CHILD },
{ GTK_CSS_CHANGE_LAST_CHILD, GTK_CSS_CHANGE_PARENT_LAST_CHILD },
{ GTK_CSS_CHANGE_NTH_CHILD, GTK_CSS_CHANGE_PARENT_NTH_CHILD },
{ GTK_CSS_CHANGE_NTH_LAST_CHILD, GTK_CSS_CHANGE_PARENT_NTH_LAST_CHILD },
{ GTK_CSS_CHANGE_STATE, GTK_CSS_CHANGE_PARENT_STATE },
{ GTK_CSS_CHANGE_SIBLING_CLASS, GTK_CSS_CHANGE_PARENT_SIBLING_CLASS },
{ GTK_CSS_CHANGE_SIBLING_NAME, GTK_CSS_CHANGE_PARENT_SIBLING_NAME },
{ GTK_CSS_CHANGE_SIBLING_ID, GTK_CSS_CHANGE_PARENT_SIBLING_ID },
{ GTK_CSS_CHANGE_SIBLING_FIRST_CHILD, GTK_CSS_CHANGE_PARENT_SIBLING_FIRST_CHILD },
{ GTK_CSS_CHANGE_SIBLING_LAST_CHILD, GTK_CSS_CHANGE_PARENT_SIBLING_LAST_CHILD },
{ GTK_CSS_CHANGE_SIBLING_NTH_CHILD, GTK_CSS_CHANGE_PARENT_SIBLING_NTH_CHILD },
{ GTK_CSS_CHANGE_SIBLING_NTH_LAST_CHILD, GTK_CSS_CHANGE_PARENT_SIBLING_NTH_LAST_CHILD },
{ GTK_CSS_CHANGE_SIBLING_STATE, GTK_CSS_CHANGE_PARENT_SIBLING_STATE },
{ GTK_CSS_CHANGE_SOURCE, 0 },
{ GTK_CSS_CHANGE_PARENT_STYLE, 0 }
};
return gtk_css_change_translate (match, table, G_N_ELEMENTS (table));
#define BASE_STATES ( GTK_CSS_CHANGE_CLASS \
| GTK_CSS_CHANGE_NAME \
| GTK_CSS_CHANGE_ID \
| GTK_CSS_CHANGE_FIRST_CHILD \
| GTK_CSS_CHANGE_LAST_CHILD \
| GTK_CSS_CHANGE_NTH_CHILD \
| GTK_CSS_CHANGE_NTH_LAST_CHILD \
| GTK_CSS_CHANGE_STATE \
| GTK_CSS_CHANGE_SIBLING_CLASS \
| GTK_CSS_CHANGE_SIBLING_NAME \
| GTK_CSS_CHANGE_SIBLING_ID \
| GTK_CSS_CHANGE_SIBLING_FIRST_CHILD \
| GTK_CSS_CHANGE_SIBLING_LAST_CHILD \
| GTK_CSS_CHANGE_SIBLING_NTH_CHILD \
| GTK_CSS_CHANGE_SIBLING_NTH_LAST_CHILD \
| GTK_CSS_CHANGE_SIBLING_STATE )
#define PARENT_SHIFT 16
return (match & ~(BASE_STATES|GTK_CSS_CHANGE_SOURCE|GTK_CSS_CHANGE_PARENT_STYLE)) | ((match & BASE_STATES) << PARENT_SHIFT);
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment