[PATCH] include/wine/unicode: Avoid scanning the entire string in memrchrW
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(a)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 a4b483a..8ee84e4 100644 --- a/include/wine/unicode.h +++ b/include/wine/unicode.h @@ -291,10 +291,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.20.1
participants (1)
-
Gabriel Ivăncescu