糯米

TI DaVinci, gstreamer, ffmpeg
随笔 - 167, 文章 - 0, 评论 - 47, 引用 - 0
数据加载中……

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

posted on 2011-09-14 22:00 糯米 阅读(400) 评论(0)  编辑 收藏 引用 所属分类: Algorithm


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理