[PATCH v2 2/4] comctl32/listbox: Rewrite FindString to use helpers and avoid the macro
Gabriel Ivăncescu
gabrielopcode at gmail.com
Tue Feb 26 06:53:36 CST 2019
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
no-op patch.
This has been cleaned up so now all the comparison code (for each of the
3 variants) is only written once because the outer loop will wrap around,
which also avoids the ugly macro. Of course it also uses the helpers and
avoids having a pointless item variable (especially since we already tracked
the index to begin with).
dlls/comctl32/listbox.c | 66 ++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 30 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
index 954866a..dd29dc6 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -965,46 +965,48 @@ static INT LISTBOX_FindFileStrPos( LB_DESCR *descr, LPCWSTR str )
*/
static INT LISTBOX_FindString( LB_DESCR *descr, INT start, LPCWSTR str, BOOL exact )
{
- INT i;
- LB_ITEMDATA *item;
+ INT i, end = descr->nb_items;
if (descr->style & LBS_NODATA) return LB_ERR;
- if (start >= descr->nb_items) start = -1;
- item = descr->items + start + 1;
+ start++;
+ if (start >= descr->nb_items) start = 0;
if (HAS_STRINGS(descr))
{
if (!str || ! str[0] ) return LB_ERR;
if (exact)
{
- for (i = start + 1; i < descr->nb_items; i++, item++)
- if (!LISTBOX_lstrcmpiW( descr->locale, str, item->str )) return i;
- for (i = 0, item = descr->items; i <= start; i++, item++)
- if (!LISTBOX_lstrcmpiW( descr->locale, str, item->str )) return i;
+ for (;;)
+ {
+ for (i = start; i < end; i++)
+ if (!LISTBOX_lstrcmpiW(descr->locale, str, get_item_string(descr, i)))
+ return i;
+ if (!start) break;
+ end = start;
+ start = 0;
+ }
}
else
{
- /* Special case for drives and directories: ignore prefix */
-#define CHECK_DRIVE(item) \
- if ((item)->str[0] == '[') \
- { \
- if (!strncmpiW( str, (item)->str+1, len )) return i; \
- if (((item)->str[1] == '-') && !strncmpiW(str, (item)->str+2, len)) \
- return i; \
- }
-
+ /* Special case for drives and directories: ignore prefix */
INT len = strlenW(str);
- for (i = start + 1; i < descr->nb_items; i++, item++)
+ for (;;)
{
- if (!strncmpiW( str, item->str, len )) return i;
- CHECK_DRIVE(item);
- }
- for (i = 0, item = descr->items; i <= start; i++, item++)
- {
- if (!strncmpiW( str, item->str, len )) return i;
- CHECK_DRIVE(item);
+ for (i = start; i < end; i++)
+ {
+ WCHAR *item_str = get_item_string(descr, i);
+
+ if (!strncmpiW(str, item_str, len)) return i;
+ if (item_str[0] == '[')
+ {
+ if (!strncmpiW(str, item_str + 1, len)) return i;
+ if (item_str[1] == '-' && !strncmpiW(str, item_str + 2, len)) return i;
+ }
+ }
+ if (!start) break;
+ end = start;
+ start = 0;
}
-#undef CHECK_DRIVE
}
}
else
@@ -1014,10 +1016,14 @@ static INT LISTBOX_FindString( LB_DESCR *descr, INT start, LPCWSTR str, BOOL exa
return LISTBOX_FindStringPos( descr, str, TRUE );
/* Otherwise use a linear search */
- for (i = start + 1; i < descr->nb_items; i++, item++)
- if (item->data == (ULONG_PTR)str) return i;
- for (i = 0, item = descr->items; i <= start; i++, item++)
- if (item->data == (ULONG_PTR)str) return i;
+ for (;;)
+ {
+ for (i = start; i < end; i++)
+ if (get_item_data(descr, i) == (ULONG_PTR)str) return i;
+ if (!start) break;
+ end = start;
+ start = 0;
+ }
}
return LB_ERR;
}
--
2.20.1
More information about the wine-devel
mailing list