mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Fix error in original commit
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18994 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f139273ffa
commit
95dde97de2
3 changed files with 36 additions and 27 deletions
|
@ -38,7 +38,6 @@ typedef unsigned short unichar;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NSMaximumStringLength (INT_MAX-1)
|
#define NSMaximumStringLength (INT_MAX-1)
|
||||||
#define NSHashStringLength 63
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|
|
@ -3807,19 +3807,16 @@ agree, create a new GSUnicodeInlineString otherwise.
|
||||||
*/
|
*/
|
||||||
- (unsigned) hash
|
- (unsigned) hash
|
||||||
{
|
{
|
||||||
unsigned ret = 0;
|
unsigned ret = 0;
|
||||||
|
unsigned len = _self->_count;
|
||||||
|
|
||||||
int len = _self->_count;
|
if (len > 0)
|
||||||
|
|
||||||
if (len > NSHashStringLength)
|
|
||||||
len = NSHashStringLength;
|
|
||||||
if (len)
|
|
||||||
{
|
{
|
||||||
const unsigned char *p;
|
const unsigned char *p;
|
||||||
unsigned char_count = 0;
|
unsigned char_count = 0;
|
||||||
|
|
||||||
p = _self->_contents.c;
|
p = _self->_contents.c;
|
||||||
while (*p != 0 && char_count++ < NSHashStringLength)
|
while (char_count++ < len)
|
||||||
{
|
{
|
||||||
unichar c = *p++;
|
unichar c = *p++;
|
||||||
|
|
||||||
|
@ -3835,9 +3832,13 @@ agree, create a new GSUnicodeInlineString otherwise.
|
||||||
* an empty cache value, so we MUST NOT return a hash of zero.
|
* an empty cache value, so we MUST NOT return a hash of zero.
|
||||||
*/
|
*/
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
ret = 0x0fffffff;
|
{
|
||||||
|
ret = 0x0fffffff;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ret &= 0x0fffffff;
|
{
|
||||||
|
ret &= 0x0fffffff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -2161,29 +2161,32 @@ handle_printf_atsign (FILE *stream,
|
||||||
*/
|
*/
|
||||||
- (unsigned int) hash
|
- (unsigned int) hash
|
||||||
{
|
{
|
||||||
unsigned ret = 0;
|
unsigned ret = 0;
|
||||||
|
unsigned len = [self length];
|
||||||
|
|
||||||
int len = [self length];
|
|
||||||
|
|
||||||
if (len > NSHashStringLength)
|
|
||||||
{
|
|
||||||
len = NSHashStringLength;
|
|
||||||
}
|
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
unichar buf[len * MAXDEC + 1];
|
unichar buf[64];
|
||||||
GSeqStruct s = { buf, len, len * MAXDEC, 0 };
|
unichar *ptr = (len <= 64) ? buf :
|
||||||
|
NSZoneMalloc(NSDefaultMallocZone(), len * sizeof(unichar));
|
||||||
unichar *p;
|
unichar *p;
|
||||||
unsigned char_count = 0;
|
unsigned char_count = 0;
|
||||||
|
|
||||||
[self getCharacters: buf range: NSMakeRange(0,len)];
|
[self getCharacters: ptr range: NSMakeRange(0,len)];
|
||||||
GSeq_normalize(&s);
|
|
||||||
|
|
||||||
p = buf;
|
p = ptr;
|
||||||
|
|
||||||
while (*p && char_count++ < NSHashStringLength)
|
while (char_count++ < len)
|
||||||
{
|
{
|
||||||
ret = (ret << 5) + ret + *p++;
|
unichar c = *p++;
|
||||||
|
|
||||||
|
// FIXME ... should normalize composed character sequences.
|
||||||
|
ret = (ret << 5) + ret + c;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ptr != buf)
|
||||||
|
{
|
||||||
|
NSZoneFree(NSDefaultMallocZone(), ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2191,13 +2194,19 @@ handle_printf_atsign (FILE *stream,
|
||||||
* an empty cache value, so we MUST NOT return a hash of zero.
|
* an empty cache value, so we MUST NOT return a hash of zero.
|
||||||
*/
|
*/
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
ret = 0x0fffffff;
|
{
|
||||||
|
ret = 0x0fffffff;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ret &= 0x0fffffff;
|
{
|
||||||
|
ret &= 0x0fffffff;
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0x0ffffffe; /* Hash for an empty string. */
|
{
|
||||||
|
return 0x0ffffffe; /* Hash for an empty string. */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting a Shared Prefix
|
// Getting a Shared Prefix
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue