mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-11 16:50:42 +00:00
([NSArray +_setMutableConcreteClass:]): New method.
([NSArray +_mutableConcreteClass]): New method. ([NSArray -copyWithZone:]): Make is a deep copy to conform to spec; it was a shallow copy. ([NSMutableArray _setConcreteClass], [NSMutableArray_concreteClass]): Removed. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@473 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8cf15bab85
commit
bba9ead38e
1 changed files with 25 additions and 22 deletions
|
@ -31,20 +31,32 @@
|
|||
@implementation NSArray
|
||||
|
||||
static Class NSArray_concrete_class;
|
||||
static Class NSMutableArray_concrete_class;
|
||||
|
||||
+ (void) _setConcreteClass: (Class)c
|
||||
{
|
||||
NSArray_concrete_class = c;
|
||||
}
|
||||
|
||||
+ (void) _setMutableConcreteClass: (Class)c
|
||||
{
|
||||
NSMutableArray_concrete_class = c;
|
||||
}
|
||||
|
||||
+ (Class) _concreteClass
|
||||
{
|
||||
return NSArray_concrete_class;
|
||||
}
|
||||
|
||||
+ (Class) _mutableConcreteClass
|
||||
{
|
||||
return NSMutableArray_concrete_class;
|
||||
}
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
NSArray_concrete_class = [NSGArray class];
|
||||
NSMutableArray_concrete_class = [NSGMutableArray class];
|
||||
}
|
||||
|
||||
+ allocWithZone: (NSZone*)z
|
||||
|
@ -278,45 +290,37 @@ static Class NSArray_concrete_class;
|
|||
|
||||
- copyWithZone: (NSZone*)zone
|
||||
{
|
||||
return [[[self class] allocWithZone:zone] initWithArray:self];
|
||||
/* a deep copy */
|
||||
int count = [self count];
|
||||
id objects[count];
|
||||
int i;
|
||||
for (i = 0; i < count; i++)
|
||||
objects[i] = [[self objectAtIndex:i] copyWithZone:zone];
|
||||
return [[[[self class] _concreteClass] allocWithZone:zone]
|
||||
initWithObjects:objects count:count];
|
||||
}
|
||||
|
||||
/* The NSMutableCopying Protocol */
|
||||
|
||||
- mutableCopyWithZone: (NSZone*)zone
|
||||
{
|
||||
return [[NSGMutableArray allocWithZone:zone] initWithArray:self];
|
||||
/* a shallow copy */
|
||||
return [[[[self class] _mutableConcreteClass] allocWithZone:zone]
|
||||
initWithArray:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSMutableArray: NSArray
|
||||
|
||||
static Class NSMutableArray_concrete_class;
|
||||
|
||||
+ (void) _setConcreteClass: (Class)c
|
||||
{
|
||||
NSMutableArray_concrete_class = c;
|
||||
}
|
||||
|
||||
+ (Class) _concreteClass
|
||||
{
|
||||
return NSMutableArray_concrete_class;
|
||||
}
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
NSMutableArray_concrete_class = [NSGMutableArray class];
|
||||
}
|
||||
|
||||
+ allocWithZone: (NSZone*)z
|
||||
{
|
||||
return NSAllocateObject([self _concreteClass], 0, z);
|
||||
return NSAllocateObject([self _mutableConcreteClass], 0, z);
|
||||
}
|
||||
|
||||
+ arrayWithCapacity: (unsigned)numItems
|
||||
{
|
||||
return [[[[self _concreteClass] alloc] initWithCapacity:numItems]
|
||||
return [[[[self _mutableConcreteClass] alloc] initWithCapacity:numItems]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
|
@ -426,4 +430,3 @@ static Class NSMutableArray_concrete_class;
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
Loading…
Reference in a new issue