Bugfix update

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2885 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1998-07-30 16:34:32 +00:00
parent 8dde889542
commit d987db52d2
6 changed files with 114 additions and 65 deletions

View file

@ -111,6 +111,63 @@ static Class NSMutableDictionary_concrete_class;
return nil;
}
- copyWithZone: (NSZone*)z
{
/* a deep copy */
unsigned count = [self count];
id oldKeys[count];
id newKeys[count];
id oldObjects[count];
id newObjects[count];
id newDictionary;
unsigned i;
id key;
NSEnumerator *enumerator = [self keyEnumerator];
BOOL needCopy = [self isKindOfClass: [NSMutableDictionary class]];
if (NSShouldRetainWithZone(self, z) == NO)
needCopy = YES;
for (i = 0; (key = [enumerator nextObject]); i++)
{
oldKeys[i] = key;
oldObjects[i] = [self objectForKey:key];
newKeys[i] = [oldKeys[i] copyWithZone:z];
newObjects[i] = [oldObjects[i] copyWithZone:z];
if (oldKeys[i] != newKeys[i] || oldObjects[i] != newObjects[i])
needCopy = YES;
}
if (needCopy)
newDictionary = [[[[self class] _concreteClass] alloc]
initWithObjects:newObjects
forKeys:newKeys
count:count];
else
newDictionary = [self retain];
for (i = 0; i < count; i++)
{
[newKeys[i] release];
[newObjects[i] release];
}
return newDictionary;
}
- mutableCopyWithZone: (NSZone*)z
{
/* a shallow copy */
return [[[[[self class] _mutableConcreteClass] _mutableConcreteClass] alloc]
initWithDictionary:self];
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[self subclassResponsibility:_cmd];
}
- (id) initWithCoder: (NSCoder*)aCoder
{
[self subclassResponsibility:_cmd];
return nil;
}
@end
@implementation NSDictionaryNonCore
@ -203,6 +260,12 @@ static Class NSMutableDictionary_concrete_class;
autorelease];
}
+ dictionaryWithObject: (id)object forKey: (id)key
{
return [[[self alloc] initWithObjects: &object forKeys: &key count: 1]
autorelease];
}
/* Override superclass's designated initializer */
- init
{
@ -365,53 +428,6 @@ compareIt(id o1, id o2, void* context)
return [[self description] writeToFile:path atomically:useAuxiliaryFile];
}
- copyWithZone: (NSZone*)z
{
/* a deep copy */
unsigned count = [self count];
id oldKeys[count];
id newKeys[count];
id oldObjects[count];
id newObjects[count];
id newDictionary;
unsigned i;
id key;
NSEnumerator *enumerator = [self keyEnumerator];
BOOL needCopy = [self isKindOfClass: [NSMutableDictionary class]];
if (NSShouldRetainWithZone(self, z) == NO)
needCopy = YES;
for (i = 0; (key = [enumerator nextObject]); i++)
{
oldKeys[i] = key;
oldObjects[i] = [self objectForKey:key];
newKeys[i] = [oldKeys[i] copyWithZone:z];
newObjects[i] = [oldObjects[i] copyWithZone:z];
if (oldKeys[i] != newKeys[i] || oldObjects[i] != newObjects[i])
needCopy = YES;
}
if (needCopy)
newDictionary = [[[[self class] _concreteClass] alloc]
initWithObjects:newObjects
forKeys:newKeys
count:count];
else
newDictionary = [self retain];
for (i = 0; i < count; i++)
{
[newKeys[i] release];
[newObjects[i] release];
}
return newDictionary;
}
- mutableCopyWithZone: (NSZone*)z
{
/* a shallow copy */
return [[[[[self class] _mutableConcreteClass] _mutableConcreteClass] alloc]
initWithDictionary:self];
}
- (NSString*) description
{
return [self descriptionWithLocale: nil];