=?UTF-8?Q?Gabriel=20Iv=C4=83ncescu=20?=: user32/listbox: Rewrite FindString to use helpers and avoid the macro.
Alexandre Julliard
julliard at winehq.org
Fri Mar 1 16:42:09 CST 2019
Module: wine
Branch: master
Commit: 18a6e37ce1116471bb60091f519ed4e88341da08
URL: https://source.winehq.org/git/wine.git/?a=commit;h=18a6e37ce1116471bb60091f519ed4e88341da08
Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date: Thu Feb 28 15:10:28 2019 +0200
user32/listbox: Rewrite FindString to use helpers and avoid the macro.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/user32/listbox.c | 57 ++++++++++++++++++++++++---------------------------
1 file changed, 27 insertions(+), 30 deletions(-)
diff --git a/dlls/user32/listbox.c b/dlls/user32/listbox.c
index 9bf9f90..75257ad 100644
--- a/dlls/user32/listbox.c
+++ b/dlls/user32/listbox.c
@@ -1003,8 +1003,7 @@ 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, index;
if (descr->style & LBS_NODATA)
{
@@ -1012,41 +1011,38 @@ static INT LISTBOX_FindString( LB_DESCR *descr, INT start, LPCWSTR str, BOOL exa
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 (i = 0, index = start; i < descr->nb_items; i++, index++)
+ {
+ if (index == descr->nb_items) index = 0;
+ if (!LISTBOX_lstrcmpiW(descr->locale, str, get_item_string(descr, index)))
+ return index;
+ }
}
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++)
- {
- if (!strncmpiW( str, item->str, len )) return i;
- CHECK_DRIVE(item);
- }
- for (i = 0, item = descr->items; i <= start; i++, item++)
+ WCHAR *item_str;
+
+ for (i = 0, index = start; i < descr->nb_items; i++, index++)
{
- if (!strncmpiW( str, item->str, len )) return i;
- CHECK_DRIVE(item);
+ if (index == descr->nb_items) index = 0;
+ item_str = get_item_string(descr, index);
+
+ if (!strncmpiW(str, item_str, len)) return index;
+ if (item_str[0] == '[')
+ {
+ if (!strncmpiW(str, item_str + 1, len)) return index;
+ if (item_str[1] == '-' && !strncmpiW(str, item_str + 2, len)) return index;
+ }
}
-#undef CHECK_DRIVE
}
}
else
@@ -1056,10 +1052,11 @@ 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 (i = 0, index = start; i < descr->nb_items; i++, index++)
+ {
+ if (index == descr->nb_items) index = 0;
+ if (get_item_data(descr, index) == (ULONG_PTR)str) return index;
+ }
}
return LB_ERR;
}
More information about the wine-cvs
mailing list