From cfce06eb88d88e84b363cefd4826ac7aa44bbfd6 Mon Sep 17 00:00:00 2001 From: Lars Hanisch Date: Wed, 15 Jun 2011 23:42:08 +0200 Subject: exit loop while search for free index as soon as possible --- dynamicdevice.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dynamicdevice.c b/dynamicdevice.c index 0c290cd..4910f9b 100644 --- a/dynamicdevice.c +++ b/dynamicdevice.c @@ -17,12 +17,15 @@ int cDynamicDevice::IndexOf(const char *DevPath, int &NextFreeIndex, int WishInd cMutexLock lock(&arrayMutex); NextFreeIndex = -1; int index = -1; - for (int i = 0; (i < numDynamicDevices) && ((index < 0) || (NextFreeIndex < 0) || ((WishIndex >= 0) && (dynamicdevice[i]->CardIndex() != WishIndex))); i++) { + for (int i = 0; (i < numDynamicDevices) && ((index < 0) || (NextFreeIndex < 0) || (WishIndex >= 0)); i++) { if (dynamicdevice[i]->devpath == NULL) { if (WishIndex >= 0) isyslog("dynamite: device at slot %d has cardindex %d", i + 1, dynamicdevice[i]->CardIndex()); - if ((NextFreeIndex < 0) || ((WishIndex >= 0) && (dynamicdevice[i]->CardIndex() == WishIndex))) + if ((NextFreeIndex < 0) || ((WishIndex >= 0) && (dynamicdevice[i]->CardIndex() == WishIndex))) { NextFreeIndex = i; + if (dynamicdevice[i]->CardIndex() == WishIndex) + break; + } } else if (index < 0) { if (strcmp(DevPath, **dynamicdevice[i]->devpath) == 0) -- cgit v1.2.3