Re: [PATCH spice-gtk] main: use stable comparison function for monitors

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

 



Hi,

On 02/20/2013 06:09 PM, Hans de Goede wrote:
Hi,

On 02/20/2013 11:35 AM, Marc-André Lureau wrote:
If monitors are equal, compare them by their addresses, to get the
effect of a stable sort.
---
  gtk/channel-main.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index fe57684..f86e81d 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -973,8 +973,9 @@ static int monitors_cmp(const void *p1, const void *p2, gpointer user_data)
      const VDAgentMonConfig *m2 = p2;
      double d1 = sqrt(m1->x * m1->x + m1->y * m1->y);
      double d2 = sqrt(m2->x * m2->x + m2->y * m2->y);
+    int diff = d1 - d2;

-    return d1 - d2;
+    return diff == 0 ? (char*)p1 - (char*)p2 : diff;

I think that should be: "(char*)p2 - (char*)p1" So that if the
address of p2 is bigger they compare as p2 > p1, and qsort will
keep the order of the array the same for monitors with identical
coordinates.

After further discussion, it turns out I'm wrong. So ACK for the patch
as is.

Regards,

Hans
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]