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 )
Gabriel Ivăncescu gabrielopcode@gmail.com writes:
Scanning backwards can avoid a full scan of the entire string and makes more sense since we are looking for the last char.
It was done this way for symmetry with the other similar functions. I don't think it's necessary to change it.
On 4/22/19 6:22 PM, Alexandre Julliard wrote:
Gabriel Ivăncescu gabrielopcode@gmail.com writes:
Scanning backwards can avoid a full scan of the entire string and makes more sense since we are looking for the last char.
It was done this way for symmetry with the other similar functions. I don't think it's necessary to change it.
Yeah I realized it was probably a copy-paste thing. I think it's better this way scanning backwards, since it's less code and slightly less overhead. It also makes more sense in my opinion. But it's your call :-)