mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 17:41:05 +00:00
some optionisation of string equality test ... don't compute hash of string
unless the string is large enough to make it worthwhile. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38541 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1a8e11c350
commit
325689b04f
1 changed files with 38 additions and 20 deletions
|
@ -2992,11 +2992,11 @@ isEqual_c(GSStr self, id anObject)
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
if (GSObjCIsInstance(anObject) == NO)
|
c = object_getClass(anObject);
|
||||||
|
if (class_isMetaClass(c) == YES)
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
c = object_getClass(anObject);
|
|
||||||
if (c == NSConstantStringClass)
|
if (c == NSConstantStringClass)
|
||||||
{
|
{
|
||||||
return literalIsEqualInternal((NXConstantString*)anObject, (GSStr)self);
|
return literalIsEqualInternal((NXConstantString*)anObject, (GSStr)self);
|
||||||
|
@ -3006,15 +3006,24 @@ isEqual_c(GSStr self, id anObject)
|
||||||
GSStr other = (GSStr)anObject;
|
GSStr other = (GSStr)anObject;
|
||||||
NSRange r = {0, self->_count};
|
NSRange r = {0, self->_count};
|
||||||
|
|
||||||
/*
|
/* First see if the hash is the same - if not, we can't be equal.
|
||||||
* First see if the hash is the same - if not, we can't be equal.
|
* However, it's not worth calculating hashes unless the strings
|
||||||
|
* are fairly long.
|
||||||
*/
|
*/
|
||||||
if (self->_flags.hash == 0)
|
if (self->_count > 15)
|
||||||
self->_flags.hash = (*hashImp)((id)self, hashSel);
|
{
|
||||||
if (other->_flags.hash == 0)
|
if (self->_flags.hash == 0)
|
||||||
other->_flags.hash = (*hashImp)((id)other, hashSel);
|
self->_flags.hash = (*hashImp)((id)self, hashSel);
|
||||||
if (self->_flags.hash != other->_flags.hash)
|
if (other->_flags.hash == 0)
|
||||||
return NO;
|
other->_flags.hash = (*hashImp)((id)other, hashSel);
|
||||||
|
if (self->_flags.hash != other->_flags.hash)
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
else if (self->_flags.hash && other->_flags.hash)
|
||||||
|
{
|
||||||
|
if (self->_flags.hash != other->_flags.hash)
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do a compare depending on the type of the other string.
|
* Do a compare depending on the type of the other string.
|
||||||
|
@ -3055,11 +3064,11 @@ isEqual_u(GSStr self, id anObject)
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
if (GSObjCIsInstance(anObject) == NO)
|
c = object_getClass(anObject);
|
||||||
|
if (class_isMetaClass(c) == YES)
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
c = object_getClass(anObject);
|
|
||||||
if (c == NSConstantStringClass)
|
if (c == NSConstantStringClass)
|
||||||
{
|
{
|
||||||
return literalIsEqualInternal((NXConstantString*)anObject, (GSStr)self);
|
return literalIsEqualInternal((NXConstantString*)anObject, (GSStr)self);
|
||||||
|
@ -3069,15 +3078,24 @@ isEqual_u(GSStr self, id anObject)
|
||||||
GSStr other = (GSStr)anObject;
|
GSStr other = (GSStr)anObject;
|
||||||
NSRange r = {0, self->_count};
|
NSRange r = {0, self->_count};
|
||||||
|
|
||||||
/*
|
/* First see if the hash is the same - if not, we can't be equal.
|
||||||
* First see if the hash is the same - if not, we can't be equal.
|
* However, it's not worth calculating hashes unless the strings
|
||||||
|
* are fairly long.
|
||||||
*/
|
*/
|
||||||
if (self->_flags.hash == 0)
|
if (self->_count > 15)
|
||||||
self->_flags.hash = (*hashImp)((id)self, hashSel);
|
{
|
||||||
if (other->_flags.hash == 0)
|
if (self->_flags.hash == 0)
|
||||||
other->_flags.hash = (*hashImp)((id)other, hashSel);
|
self->_flags.hash = (*hashImp)((id)self, hashSel);
|
||||||
if (self->_flags.hash != other->_flags.hash)
|
if (other->_flags.hash == 0)
|
||||||
return NO;
|
other->_flags.hash = (*hashImp)((id)other, hashSel);
|
||||||
|
if (self->_flags.hash != other->_flags.hash)
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
else if (self->_flags.hash && other->_flags.hash)
|
||||||
|
{
|
||||||
|
if (self->_flags.hash != other->_flags.hash)
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do a compare depending on the type of the other string.
|
* Do a compare depending on the type of the other string.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue