Scanning backwards can avoid a full scan of the entire string and makes more sense since we are looking for the last char.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- include/wine/unicode.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/include/wine/unicode.h b/include/wine/unicode.h index ff6f656..671f316 100644 --- a/include/wine/unicode.h +++ b/include/wine/unicode.h @@ -287,10 +287,9 @@ WINE_UNICODE_INLINE WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n )
WINE_UNICODE_INLINE WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n ) { - const WCHAR *end; - WCHAR *ret = NULL; - for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) ret = (WCHAR *)(ULONG_PTR)ptr; - return ret; + const WCHAR *p; + for (p = ptr + n - 1; p >= ptr; p--) if (*p == ch) return (WCHAR *)(ULONG_PTR)p; + return NULL; }
WINE_UNICODE_INLINE long int atolW( const WCHAR *str )