experiment with slower but better hashes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36344 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-03-12 16:11:10 +00:00
parent 4de78bda70
commit cc87536fda
7 changed files with 429 additions and 79 deletions

View file

@ -2430,29 +2430,17 @@ static UCollator *GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *local
*/
- (NSUInteger) hash
{
unsigned ret = 0;
unsigned len = [self length];
uint32_t ret = 0;
int len = (int)[self length];
if (len > 0)
{
unichar buf[64];
unichar *ptr = (len <= 64) ? buf :
NSZoneMalloc(NSDefaultMallocZone(), len * sizeof(unichar));
unichar *p;
unsigned char_count = 0;
[self getCharacters: ptr range: NSMakeRange(0,len)];
p = ptr;
while (char_count++ < len)
{
unichar c = *p++;
// FIXME ... should normalize composed character sequences.
ret = (ret << 5) + ret + c;
}
ret = GSPrivateHash(0, (const void*)ptr, len * sizeof(unichar));
if (ptr != buf)
{
NSZoneFree(NSDefaultMallocZone(), ptr);