inetmib1: Avoid idempotent operation in findSupportedQuery function (Clang) (try 3)

Frédéric Delanoy frederic.delanoy at gmail.com
Fri Oct 14 06:02:35 CDT 2011


indexLow is always 0 at that point

try 3: use standard dichotomic search
try 2: restructured and simplified loop
---
 dlls/inetmib1/main.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/dlls/inetmib1/main.c b/dlls/inetmib1/main.c
index 76741f3..98ba79d 100644
--- a/dlls/inetmib1/main.c
+++ b/dlls/inetmib1/main.c
@@ -1343,28 +1343,27 @@ static struct mibImplementation *findSupportedQuery(UINT *ids, UINT idLength,
     UINT *matchingIndex)
 {
     int indexHigh = DEFINE_SIZEOF(supportedIDs) - 1, indexLow = 0, i;
-    struct mibImplementation *impl = NULL;
     AsnObjectIdentifier oid1 = { idLength, ids};
 
     if (!idLength)
         return NULL;
-    for (i = (indexLow + indexHigh) / 2; !impl && indexLow <= indexHigh;
-         i = (indexLow + indexHigh) / 2)
+
+    while (indexLow <= indexHigh)
     {
         INT cmp;
 
-        cmp = SnmpUtilOidNCmp(&oid1, &supportedIDs[i].name, idLength);
-        if (!cmp)
+        i = (indexLow + indexHigh) / 2;
+        if (!(cmp = SnmpUtilOidNCmp(&oid1, &supportedIDs[i].name, idLength)))
         {
-            impl = &supportedIDs[i];
             *matchingIndex = i;
+            return &supportedIDs[i];
         }
-        else if (cmp > 0)
+        if (cmp > 0)
             indexLow = i + 1;
         else
             indexHigh = i - 1;
     }
-    return impl;
+    return NULL;
 }
 
 /*****************************************************************************
-- 
1.7.7




More information about the wine-patches mailing list