From: Gabriel Ivăncescu Subject: [PATCH resend] include/wine/unicode: Avoid scanning the entire string in memrchrW Message-Id: <36c04e7e8a975420495c0cf48b84aa6263cd353f.1555933422.git.gabrielopcode@gmail.com> Date: Mon, 22 Apr 2019 14:49:03 +0300 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 --- 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 ) -- 2.21.0