Avoid excess copies of dictionary keys

This commit is contained in:
rfm 2024-06-19 12:07:16 +01:00
parent 7c4a7469a9
commit 5dbec4e707

View file

@ -235,6 +235,10 @@ static SEL objSel;
NSUInteger c = [other count];
GSIMapInitWithZoneAndCapacity(&map, z, c);
if (nil == other || other == self)
{
return self;
}
if (c > 0)
{
NSEnumerator *e = [other keyEnumerator];
@ -251,21 +255,14 @@ static SEL objSel;
if (isProxy == YES)
{
k = [e nextObject];
if (nil == (k = [e nextObject])) break;
o = [other objectForKey: k];
}
else
{
k = (*nxtObj)(e, nxtSel);
if (nil == (k = (*nxtObj)(e, nxtSel))) break;
o = (*otherObj)(other, objSel, k);
}
k = [k copyWithZone: z];
if (k == nil)
{
DESTROY(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to init dictionary with nil key"];
}
if (shouldCopy)
{
o = [o copyWithZone: z];
@ -274,12 +271,6 @@ static SEL objSel;
{
o = RETAIN(o);
}
if (o == nil)
{
DESTROY(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to init dictionary with nil value"];
}
node = GSIMapNodeForKey(&map, (GSIMapKey)k);
if (node)
@ -289,7 +280,8 @@ static SEL objSel;
}
else
{
GSIMapAddPairNoRetain(&map, (GSIMapKey)k, (GSIMapVal)o);
GSIMapAddPair(&map, (GSIMapKey)k, (GSIMapVal)o);
RELEASE(o);
}
}
}