From 83f950a1be6bde17330256b1d3e3873c94a95703 Mon Sep 17 00:00:00 2001 From: Ignacio Casal Quinteiro Date: Wed, 24 Dec 2014 23:00:52 +0100 Subject: context: minor optmization of the rescan Add the devices after removing the ones that do not exists anymore, this way we avoid checking the new ones. --- gusb/gusb-context.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gusb') diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c index 5ced2a1..52536ba 100644 --- a/gusb/gusb-context.c +++ b/gusb/gusb-context.c @@ -374,11 +374,6 @@ g_usb_context_rescan (GUsbContext *context) guint i; libusb_device **dev_list = NULL; - /* add any devices not yet added (duplicates will be filtered */ - libusb_get_device_list (priv->ctx, &dev_list); - for (i = 0; dev_list && dev_list[i]; i++) - g_usb_context_add_device (context, dev_list[i]); - /* copy to a context so we can remove from the array */ for (i = 0; i < priv->devices->len; i++) { device = g_ptr_array_index (priv->devices, i); @@ -402,6 +397,11 @@ g_usb_context_rescan (GUsbContext *context) } } + /* add any devices not yet added (duplicates will be filtered */ + libusb_get_device_list (priv->ctx, &dev_list); + for (i = 0; dev_list && dev_list[i]; i++) + g_usb_context_add_device (context, dev_list[i]); + g_list_free (existing_devices); libusb_free_device_list (dev_list, 1); } -- cgit v1.2.1