[gtk+] css selector: Take advantage of interned strings



commit 11d3582333bb80546e0b94271c14be89069f2a0d
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Sep 10 20:04:24 2015 -0400

    css selector: Take advantage of interned strings
    
    We know these strings are interned, no need to use strcmp or
    g_str_hash for hem.

 gtk/gtkcssselector.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index eed04f7..aa279b2 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -778,13 +778,12 @@ static int
 gtk_css_selector_region_compare_one (const GtkCssSelector *a,
                                     const GtkCssSelector *b)
 {
-  int diff;
-
-  diff = strcmp (a->region.name, b->region.name);
-  if (diff)
-    return diff;
-
-  return a->region.flags - b->region.flags;
+  if (a->region.name < b->region.name)
+    return -1;
+  else if (a->region.name > b->region.name)
+    return 1;
+  else
+    return a->region.flags - b->region.flags;
 }
 
 static const GtkCssSelectorClass GTK_CSS_SELECTOR_REGION = {
@@ -851,14 +850,19 @@ match_id (const GtkCssSelector *selector,
 static guint
 hash_id (const GtkCssSelector *a)
 {
-  return g_str_hash (a->id.name);
+  return GPOINTER_TO_UINT (a->id.name);
 }
 
 static int
 comp_id (const GtkCssSelector *a,
         const GtkCssSelector *b)
 {
-  return strcmp (a->id.name, b->id.name);
+  if (a->id.name < b->id.name)
+    return -1;
+  else if (a->id.name > b->id.name)
+    return 1;
+  else
+    return 0;
 }
 
 DEFINE_SIMPLE_SELECTOR(id, ID, print_id, match_id, hash_id, comp_id, TRUE, FALSE, FALSE)


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