[gtk+] More bit manipulation speedups



commit 59797754b47214a1268a20bdda99afbf5d3d93fb
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Sep 9 14:09:21 2015 -0400

    More bit manipulation speedups
    
    The same trick that was applied to _gtk_css_change_for_child in
    the previous commit can be applied to _gtk_css_change_for_sibling
    as well, and that is what this commit does.
    
    With both functions converted, gtk_css_change_translate is no
    longer needed and gets dropped.

 gtk/gtkcsstypes.c |   56 ++++++++++++++++------------------------------------
 1 files changed, 17 insertions(+), 39 deletions(-)
---
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index 3a84870..e14ab2c 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -22,49 +22,24 @@
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkstylecontextprivate.h"
 
-typedef struct _GtkCssChangeTranslation GtkCssChangeTranslation;
-struct _GtkCssChangeTranslation {
-  GtkCssChange from;
-  GtkCssChange to;
-};
-
-static GtkCssChange
-gtk_css_change_translate (GtkCssChange                   match,
-                         const GtkCssChangeTranslation *translations,
-                         guint                         n_translations)
-{
-  GtkCssChange result = match;
-  guint i;
-
-  for (i = 0; i < n_translations; i++)
-    {
-      if (match & translations[i].from)
-        {
-          result &= ~translations[i].from;
-          result |= translations[i].to;
-        }
-    }
-
-  return result;
-}
-
 GtkCssChange
 _gtk_css_change_for_sibling (GtkCssChange match)
 {
-  static const GtkCssChangeTranslation table[] = {
-    { GTK_CSS_CHANGE_CLASS, GTK_CSS_CHANGE_SIBLING_CLASS },
-    { GTK_CSS_CHANGE_NAME, GTK_CSS_CHANGE_SIBLING_NAME },
-    { GTK_CSS_CHANGE_ID, GTK_CSS_CHANGE_SIBLING_ID },
-    { GTK_CSS_CHANGE_FIRST_CHILD, GTK_CSS_CHANGE_SIBLING_FIRST_CHILD },
-    { GTK_CSS_CHANGE_LAST_CHILD, GTK_CSS_CHANGE_SIBLING_LAST_CHILD },
-    { GTK_CSS_CHANGE_NTH_CHILD, GTK_CSS_CHANGE_NTH_CHILD | GTK_CSS_CHANGE_SIBLING_NTH_CHILD },
-    { GTK_CSS_CHANGE_NTH_LAST_CHILD, GTK_CSS_CHANGE_NTH_LAST_CHILD | GTK_CSS_CHANGE_SIBLING_NTH_LAST_CHILD },
-    { GTK_CSS_CHANGE_STATE, GTK_CSS_CHANGE_SIBLING_STATE },
-    { GTK_CSS_CHANGE_SOURCE, 0 },
-    { GTK_CSS_CHANGE_PARENT_STYLE, 0 }
-  };
+#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 )
+
+#define SIBLING_SHIFT 8
 
-  return gtk_css_change_translate (match, table, G_N_ELEMENTS (table)); 
+  return (match & ~(BASE_STATES|GTK_CSS_CHANGE_SOURCE|GTK_CSS_CHANGE_PARENT_STYLE)) | ((match & BASE_STATES) 
<< SIBLING_SHIFT);
+
+#undef BASE_STATES
+#undef SIBLING_SHIFT
 }
 
 GtkCssChange
@@ -90,6 +65,9 @@ _gtk_css_change_for_child (GtkCssChange match)
 #define PARENT_SHIFT 16
 
   return (match & ~(BASE_STATES|GTK_CSS_CHANGE_SOURCE|GTK_CSS_CHANGE_PARENT_STYLE)) | ((match & BASE_STATES) 
<< PARENT_SHIFT);
+
+#undef BASE_STATES
+#undef PARENT_SHIFT
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]