Optimise test for dictionary equality

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@15973 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2003-02-16 11:31:28 +00:00
parent bfed503388
commit 64d7feafd2
4 changed files with 93 additions and 2 deletions

View file

@ -244,6 +244,42 @@ static SEL objSel;
return self;
}
- (BOOL) isEqualToDictionary: (NSDictionary*)other
{
unsigned count;
if (other == self)
{
return YES;
}
count = map.nodeCount;
if (count == [other count])
{
if (count > 0)
{
GSIMapEnumerator_t enumerator;
GSIMapNode node;
IMP otherObj = [other methodForSelector: objSel];
enumerator = GSIMapEnumeratorForMap(&map);
while ((node = GSIMapEnumeratorNextNode(&enumerator)) != 0)
{
id o1 = node->value.obj;
id o2 = (*otherObj)(other, objSel, node->key.obj);
if (o1 != o2 && [o1 isEqual: o2] == NO)
{
GSIMapEndEnumerator(&enumerator);
return NO;
}
}
GSIMapEndEnumerator(&enumerator);
}
return YES;
}
return NO;
}
- (NSEnumerator*) keyEnumerator
{
return AUTORELEASE([[GSDictionaryKeyEnumerator allocWithZone: