On Wed, Aug 10, 2016 at 01:50:53PM +0200, Simon Wydooghe wrote:
> This is the patch I made to nm-device.c:
> 
> --- nm-device.c 2016-08-10 13:45:09.000000000 +0200
> +++ nm-device_patched.c 2016-08-10 13:46:30.408878875 +0200
> @@ -1267,7 +1267,7 @@
>                 s_con = nm_connection_get_setting_connection (connection);
>                 g_assert (s_con);
>                 if (nm_setting_connection_get_autoconnect (s_con))
> -                       available_conns = g_slist_prepend (available_conns,
> connection);
> +                       available_conns = g_slist_append (available_conns,
> connection);
>         }
> 
>         if (!available_conns)
> 

This seems correct, as auto_activate_device() calls
nm_settings_get_connections() which sorts connections by decreasing
timestamp and thus @connections in
nm_device_get_best_auto_connection() are already in the 'right' order;
while looping through the elements we must maintain the same order
also in @available_conns.

As appending to a GSList in a loop becomes O(n^2), you could instead
add a:

 available_conns = g_slist_reverse (available_conns);

after
        if (!available_conns)
                return NULL;

to make it a bit more efficient [1]. But probably the improvement is
non-existent for small connection numbers, so either way is fine.

Beniamino

[1] 
https://developer.gnome.org/glib/stable/glib-Singly-Linked-Lists.html#g-slist-append

Attachment: signature.asc
Description: PGP signature

_______________________________________________
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to