diff --git a/uppsrc/Core/Defs.h b/uppsrc/Core/Defs.h index 12d571627..75a79606d 100644 --- a/uppsrc/Core/Defs.h +++ b/uppsrc/Core/Defs.h @@ -811,11 +811,16 @@ force_inline bool svo_memeq(const tchar *a, const tchar *b, int len) return true; } +#if defined(CPU_UNALIGNED) && defined(CPU_LE) && (defined(COMPILER_MSC) || defined(COMPILER_GCC)) +#define FAST_STRING_COMPARE +#endif + +#ifdef FAST_STRING_COMPARE force_inline -int fast_memcmp(byte *a, byte *b, size_t len) +int fast_memcmp(const char *a, const char *b, size_t len) { #ifdef CPU_64 - while(len > 8) { + while(len >= 8) { uint64 a64 = *(uint64 *)a; uint64 b64 = *(uint64 *)b; if(a64 != b64) @@ -824,7 +829,7 @@ int fast_memcmp(byte *a, byte *b, size_t len) b += 8; len -= 8; } - if(len > 4) { + if(len >= 4) { uint32 a32 = *(uint32 *)a; uint32 b32 = *(uint32 *)b; if(a32 != b32) @@ -834,7 +839,7 @@ int fast_memcmp(byte *a, byte *b, size_t len) len -= 4; } #else - while(len > 4) { + while(len >= 4) { uint32 a32 = *(uint32 *)a; uint32 b32 = *(uint32 *)b; if(a32 != b32) @@ -844,7 +849,7 @@ int fast_memcmp(byte *a, byte *b, size_t len) len -= 4; } #endif - if(len > 2) { + if(len >= 2) { uint16 a16 = *(uint16 *)a; uint16 b16 = *(uint16 *)b; if(a16 != b16) @@ -857,7 +862,13 @@ int fast_memcmp(byte *a, byte *b, size_t len) return *a < *b ? -1 : 1; return 0; } - +#else +inline +int fast_memcmp(const char *a, const char *b, size_t len) +{ + return memcmp(a, b, len); +} +#endif //Quick fix.... #ifdef PLATFORM_WINCE diff --git a/uppsrc/Core/String.cpp b/uppsrc/Core/String.cpp index 03581dc67..7da1b5306 100644 --- a/uppsrc/Core/String.cpp +++ b/uppsrc/Core/String.cpp @@ -90,11 +90,8 @@ int String0::LCompare(const String0& s) const int la = GetLength(); const char *b = s.Begin(); int lb = s.GetLength(); - int l = min(la, lb); - for(int i = 0; i < l; i++) { - int q = (byte)a[i] - (byte)b[i]; - if(q) return q; - } + int q = fast_memcmp(a, b, min(la, lb)); + if(q) return q; return la - lb; } diff --git a/uppsrc/Core/String.h b/uppsrc/Core/String.h index f4b2909e6..336f9f577 100644 --- a/uppsrc/Core/String.h +++ b/uppsrc/Core/String.h @@ -1,9 +1,5 @@ class Nuller; -#if defined(CPU_X86) && (defined(COMPILER_MSC) || defined(COMPILER_GCC)) -#define FAST_STRING_COMPARE -#endif - int wstrlen(const wchar *s); #ifdef PLATFORM_POSIX