[gtk+/gtk-style-context: 185/260] GtkStyleContext: Return insertion	position if not found when matching classes/regions
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc: 
- Subject: [gtk+/gtk-style-context: 185/260] GtkStyleContext: Return insertion	position if not found when matching classes/regions
- Date: Wed, 20 Oct 2010 10:36:59 +0000 (UTC)
commit 73d1c2b145c08b3c53e8b57b55a1b8e2c16b532f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Aug 16 19:08:11 2010 +0200
    GtkStyleContext: Return insertion position if not found when matching classes/regions
 gtk/gtkstylecontext.c |   40 ++++++++++++++++++++++++----------------
 1 files changed, 24 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index f944014..41b607f 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -705,6 +705,7 @@ style_class_find (GArray *array,
 {
   gint min, max, mid;
   gboolean found = FALSE;
+  guint pos;
 
   if (position)
     *position = 0;
@@ -719,23 +720,26 @@ style_class_find (GArray *array,
     {
       GQuark item;
 
-      mid = min + max / 2;
+      mid = (min + max) / 2;
       item = g_array_index (array, GQuark, mid);
 
       if (class_quark == item)
-        found = TRUE;
+        {
+          found = TRUE;
+          pos = mid;
+        }
       else if (class_quark > item)
-        min = mid = mid + 1;
+        min = pos = mid + 1;
       else
-        max = mid = mid - 1;
+        {
+          max = mid - 1;
+          pos = mid;
+        }
     }
   while (!found && min <= max);
 
-  if (mid < 0)
-    mid = 0;
-
   if (position)
-    *position = mid;
+    *position = pos;
 
   return found;
 }
@@ -747,6 +751,7 @@ region_find (GArray *array,
 {
   gint min, max, mid;
   gboolean found = FALSE;
+  guint pos;
 
   if (position)
     *position = 0;
@@ -761,23 +766,26 @@ region_find (GArray *array,
     {
       GtkRegion *region;
 
-      mid = min + max / 2;
+      mid = (min + max) / 2;
       region = &g_array_index (array, GtkRegion, mid);
 
       if (region->class_quark == class_quark)
-        found = TRUE;
+        {
+          found = TRUE;
+          pos = mid;
+        }
       else if (region->class_quark > class_quark)
-        min = mid = mid + 1;
+        min = pos = mid + 1;
       else
-        max = mid = mid - 1;
+        {
+          max = mid - 1;
+          pos = mid;
+        }
     }
   while (!found && min <= max);
 
-  if (mid < 0)
-    mid = 0;
-
   if (position)
-    *position = mid;
+    *position = pos;
 
   return found;
 }
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]