str_fastcmp
摘自:luajit源码lj_str.c
/*
Fast string data comparison. Caveat: unaligned access to 1st string!
*/
static LJ_AINLINE int str_fastcmp( const char * a, const char * b, MSize len)
{
MSize i = 0 ;
lua_assert(len > 0 );
lua_assert((((uintptr_t)a + len) & (LJ_PAGESIZE - 1 )) <= LJ_PAGESIZE - 4 );
do { /* Note: innocuous access up to end of string + 3. */
uint32_t v = lj_getu32(a + i) ^ * ( const uint32_t * )(b + i);
if (v) {
i -= len;
#if LJ_LE
return (int32_t)i >= - 3 ? (v << ( 32 + (i << 3 ))) : 1 ;
#else
return (int32_t)i >= - 3 ? (v >> ( 32 + (i << 3 ))) : 1 ;
#endif
}
i += 4 ;
} while (i < len);
return 0 ;
}
static LJ_AINLINE int str_fastcmp( const char * a, const char * b, MSize len)
{
MSize i = 0 ;
lua_assert(len > 0 );
lua_assert((((uintptr_t)a + len) & (LJ_PAGESIZE - 1 )) <= LJ_PAGESIZE - 4 );
do { /* Note: innocuous access up to end of string + 3. */
uint32_t v = lj_getu32(a + i) ^ * ( const uint32_t * )(b + i);
if (v) {
i -= len;
#if LJ_LE
return (int32_t)i >= - 3 ? (v << ( 32 + (i << 3 ))) : 1 ;
#else
return (int32_t)i >= - 3 ? (v >> ( 32 + (i << 3 ))) : 1 ;
#endif
}
i += 4 ;
} while (i < len);
return 0 ;
}