Branch: Tag:

2011-05-01

2011-05-01 03:20:50 by Per Hedbor <ph@opera.com>

Check strings for magnitude in the forward, not backward, direction.

This saves a few % of CPU for short (<1Kb) strings, but not for long ones
(I guess the hardware prefetcher catches on rather quickly)

102:      #define StrHash(s,len) low_do_hash(s,len,0)    - static INLINE size_t low_do_hash(const void *s, + static size_t low_do_hash(const void *s,    ptrdiff_t len__,    int size_shift)   {
119:      static INLINE int find_magnitude1(const p_wchar1 *s, ptrdiff_t len)   { -  while(--len>=0) -  if(s[len]>=256) +  const p_wchar1 *e=s+len; +  while(s<e) +  if(*s++>=256)    return 1;    return 0;   }      static INLINE int find_magnitude2(const p_wchar2 *s, ptrdiff_t len)   { -  while(--len>=0) +  const p_wchar2 *e=s+len; +  while(s<e)    { -  if((unsigned INT32)s[len]>=256) +  if((unsigned INT32)*s++>=256)    {    do    { -  if((unsigned INT32)s[len]>=65536) +  if((unsigned INT32)*s++>=65536)    return 2; -  }while(--len>=0); +  }while(s<e);    return 1;    }    }