mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-14 10:00:55 +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
|
@implementation NSArray
|
||||||
|
|
||||||
static Class NSArray_concrete_class;
|
static Class NSArray_concrete_class;
|
||||||
|
static Class NSMutableArray_concrete_class;
|
||||||
|
|
||||||
+ (void) _setConcreteClass: (Class)c
|
+ (void) _setConcreteClass: (Class)c
|
||||||
{
|
{
|
||||||
NSArray_concrete_class = c;
|
NSArray_concrete_class = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (void) _setMutableConcreteClass: (Class)c
|
||||||
|
{
|
||||||
|
NSMutableArray_concrete_class = c;
|
||||||
|
}
|
||||||
|
|
||||||
+ (Class) _concreteClass
|
+ (Class) _concreteClass
|
||||||
{
|
{
|
||||||
return NSArray_concrete_class;
|
return NSArray_concrete_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (Class) _mutableConcreteClass
|
||||||
|
{
|
||||||
|
return NSMutableArray_concrete_class;
|
||||||
|
}
|
||||||
|
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
NSArray_concrete_class = [NSGArray class];
|
NSArray_concrete_class = [NSGArray class];
|
||||||
|
NSMutableArray_concrete_class = [NSGMutableArray class];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ allocWithZone: (NSZone*)z
|
+ allocWithZone: (NSZone*)z
|
||||||
|
@ -278,45 +290,37 @@ static Class NSArray_concrete_class;
|
||||||
|
|
||||||
- copyWithZone: (NSZone*)zone
|
- 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 */
|
/* The NSMutableCopying Protocol */
|
||||||
|
|
||||||
- mutableCopyWithZone: (NSZone*)zone
|
- mutableCopyWithZone: (NSZone*)zone
|
||||||
{
|
{
|
||||||
return [[NSGMutableArray allocWithZone:zone] initWithArray:self];
|
/* a shallow copy */
|
||||||
|
return [[[[self class] _mutableConcreteClass] allocWithZone:zone]
|
||||||
|
initWithArray:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSMutableArray: NSArray
|
@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
|
+ allocWithZone: (NSZone*)z
|
||||||
{
|
{
|
||||||
return NSAllocateObject([self _concreteClass], 0, z);
|
return NSAllocateObject([self _mutableConcreteClass], 0, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ arrayWithCapacity: (unsigned)numItems
|
+ arrayWithCapacity: (unsigned)numItems
|
||||||
{
|
{
|
||||||
return [[[[self _concreteClass] alloc] initWithCapacity:numItems]
|
return [[[[self _mutableConcreteClass] alloc] initWithCapacity:numItems]
|
||||||
autorelease];
|
autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,4 +430,3 @@ static Class NSMutableArray_concrete_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue