[glib: 1/2] GWin32VolumeMonitor: Sort the volumes correctly



commit 0c16230b28bf01719988f3d4c8e9281a9c009981
Author: Руслан Ижбулатов <lrn1986 gmail com>
Date:   Wed Feb 13 13:55:11 2019 +0000

    GWin32VolumeMonitor: Sort the volumes correctly
    
    Use a static GQueue to form the GList of mounts by appending (which
    is fast, because GQueue tracks the tail pointer of its internal GList),
    then return that GList. This way we don't need to form the list
    by prepending, which would have made it necessary to reverse it before
    returning.
    
    If the list is not ordered correctly, local drives in GTK places sidebar
    are shown in reverse order.

 gio/gwin32volumemonitor.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/gio/gwin32volumemonitor.c b/gio/gwin32volumemonitor.c
index c9db68a8a..512471834 100644
--- a/gio/gwin32volumemonitor.c
+++ b/gio/gwin32volumemonitor.c
@@ -111,7 +111,7 @@ get_mounts (GVolumeMonitor *volume_monitor)
 {
   DWORD   drives;
   gchar   drive[4] = "A:\\";
-  GList *list = NULL;
+  GQueue  queue = G_QUEUE_INIT;
   
   drives = get_viewable_logical_drives ();
 
@@ -121,13 +121,13 @@ get_mounts (GVolumeMonitor *volume_monitor)
   while (drives && drive[0] <= 'Z')
     {
       if (drives & 1)
-      {
-       list = g_list_prepend (list, _g_win32_mount_new (volume_monitor, drive, NULL));
-      }
+        g_queue_push_tail (&queue, _g_win32_mount_new (volume_monitor, drive, NULL));
+
       drives >>= 1;
       drive[0]++;
     }
-  return list;
+
+  return g_steal_pointer (&queue.head);
 }
 
 /* actually 'mounting' volumes is out of GIOs business on win32, so no volumes are delivered either */


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