mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Avoid excess copies of dictionary keys
This commit is contained in:
parent
7c4a7469a9
commit
5dbec4e707
1 changed files with 8 additions and 16 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue