[gtk+] Manipulate bits more efficiently
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Manipulate bits more efficiently
- Date: Wed, 9 Sep 2015 18:03:34 +0000 (UTC)
commit d7dd6eccd500402ac51c2a3d2b8f768acfa75d4a
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Sep 9 14:00:49 2015 -0400
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.
gtk/gtkcsstypes.c | 40 +++++++++++++++++++---------------------
1 files changed, 19 insertions(+), 21 deletions(-)
---
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index 3553683..3a84870 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]