mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
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:
parent
4de78bda70
commit
cc87536fda
7 changed files with 429 additions and 79 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue