ChangeSet ID: 19240 CVSROOT: /opt/cvs-commit Module name: wine Changes by: julliard@wine.codeweavers.com 2005/08/01 04:18:23 Modified files: dlls/comctl32/tests: dpa.c dlls/comctl32 : dpa.c Log message: Felix Nawothnig Fix DPA_Search for sorted arrays. Patch: http://cvs.winehq.org/patch.py?id=19240 Old revision New revision Changes Path 1.12 1.13 +1 -1 wine/dlls/comctl32/tests/dpa.c 1.2 1.3 +6 -23 wine/dlls/comctl32/dpa.c Index: wine/dlls/comctl32/tests/dpa.c diff -u -p wine/dlls/comctl32/tests/dpa.c:1.12 wine/dlls/comctl32/tests/dpa.c:1.13 --- wine/dlls/comctl32/tests/dpa.c:1.12 Sat May 18 06:55:38 2013 +++ wine/dlls/comctl32/tests/dpa.c Sat May 18 06:55:38 2013 @@ -274,7 +274,7 @@ static void test_dpa(void) j = pDPA_GetPtrIndex(dpa, (PVOID)i); ok(j+1 == i, "j=%d i=%d\n", j, i); j = pDPA_Search(dpa, (PVOID)i, 0, CB_CmpLT, 0xdeadbeef, DPAS_SORTED); - if(i > 1) todo_wine ok(j+1 == i, "j=%d i=%d\n", j, i); + ok(j+1 == i, "j=%d i=%d\n", j, i); /* Linear searches respect iStart ... */ j = pDPA_Search(dpa, (PVOID)i, i+1, CB_CmpLT, 0xdeadbeef, 0); Index: wine/dlls/comctl32/dpa.c diff -u -p wine/dlls/comctl32/dpa.c:1.2 wine/dlls/comctl32/dpa.c:1.3 --- wine/dlls/comctl32/dpa.c:1.2 Sat May 18 06:55:38 2013 +++ wine/dlls/comctl32/dpa.c Sat May 18 06:55:38 2013 @@ -787,11 +787,6 @@ BOOL WINAPI DPA_Sort (const HDPA hdpa, P * RETURNS * Success: index of the pointer in the array. * Failure: -1 - * - * NOTES - * Binary search taken from R.Sedgewick "Algorithms in C"! - * Function is NOT tested! - * If something goes wrong, blame HIM not ME! (Eric Kohl) */ INT WINAPI DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart, PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions) @@ -807,47 +802,35 @@ INT WINAPI DPA_Search (const HDPA hdpa, INT l, r, x, n; LPVOID *lpPtr; - TRACE("binary search\n"); - l = (nStart == -1) ? 0 : nStart; r = hdpa->nItemCount - 1; lpPtr = hdpa->ptrs; while (r >= l) { x = (l + r) / 2; n = (pfnCompare)(pFind, lpPtr[x], lParam); - if (n < 0) + if (n == 0) + return x; + else if (n < 0) r = x - 1; - else + else /* (n > 0) */ l = x + 1; - if (n == 0) { - TRACE("-- ret=%d\n", n); - return n; - } } - if (uOptions & (DPAS_INSERTBEFORE | DPAS_INSERTAFTER)) { - TRACE("-- ret=%d\n", l); - return l; - } + return l; } else { /* array is not sorted --> use linear search */ LPVOID *lpPtr; INT nIndex; - TRACE("linear search\n"); - nIndex = (nStart == -1)? 0 : nStart; lpPtr = hdpa->ptrs; for (; nIndex < hdpa->nItemCount; nIndex++) { - if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) { - TRACE("-- ret=%d\n", nIndex); + if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) return nIndex; - } } } - TRACE("-- not found: ret=-1\n"); return -1; }