Core: Optimizing String

git-svn-id: svn://ultimatepp.org/upp/trunk@9403 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2016-01-16 13:55:25 +00:00
parent 77a388ba8f
commit cd830c1215
3 changed files with 19 additions and 15 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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