[gtk+] Optimize gtk_css_node_declaration_has_class



commit cf0e087527f4fdc1c79649bc75361eb2e7e994f8
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Sep 9 14:40:36 2015 -0400

    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.

 gtk/gtkcssnodedeclaration.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkcssnodedeclaration.c b/gtk/gtkcssnodedeclaration.c
index 989ad94..221faef 100644
--- a/gtk/gtkcssnodedeclaration.c
+++ b/gtk/gtkcssnodedeclaration.c
@@ -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 *


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