git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@15654 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2003-01-20 17:18:06 +00:00
parent 2aafe79eee
commit 4bd6038dd5
8 changed files with 138 additions and 47 deletions

View file

@ -34,6 +34,8 @@
static SEL eqSel;
static Class GSInlineArrayClass;
@class GSArrayEnumerator;
@class GSArrayEnumeratorReverse;
@ -73,6 +75,7 @@ static SEL eqSel;
{
[self setVersion: 1];
eqSel = @selector(isEqual:);
GSInlineArrayClass = [GSInlineArray class];
}
}
@ -83,6 +86,11 @@ static SEL eqSel;
return array;
}
- (id) copyWithZone: (NSZone*)zone
{
return RETAIN(self); // Optimised version
}
- (void) dealloc
{
if (_contents_array)
@ -357,6 +365,17 @@ static SEL eqSel;
_count++; /* Do this AFTER we have retained the object. */
}
/**
* Optimised code for copying
*/
- (id) copyWithZone: (NSZone*)zone
{
NSArray *copy;
copy = (id)NSAllocateObject(GSInlineArrayClass, sizeof(id)*_count, zone);
return [copy initWithObjects: _contents_array count: _count];
}
- (void) exchangeObjectAtIndex: (unsigned int)i1
withObjectAtIndex: (unsigned int)i2
{
@ -892,8 +911,6 @@ static SEL eqSel;
@implementation GSPlaceholderArray
static Class GSInlineArrayClass;
+ (void) initialize
{
GSInlineArrayClass = [GSInlineArray class];

View file

@ -84,6 +84,11 @@ static SEL objSel;
}
}
- (id) copyWithZone: (NSZone*)zone
{
return RETAIN(self);
}
- (unsigned) count
{
return map.nodeCount;
@ -277,6 +282,13 @@ static SEL objSel;
}
}
- (id) copyWithZone: (NSZone*)zone
{
NSDictionary *copy = [GSDictionary allocWithZone: zone];
return [copy initWithDictionary: self copyItems: NO];
}
/* Designated initialiser */
- (id) initWithCapacity: (unsigned)cap
{

View file

@ -144,6 +144,11 @@ static Class mutableSetClass;
}
}
- (id) copyWithZone: (NSZone*)z
{
return RETAIN(self);
}
- (unsigned) count
{
return map.nodeCount;
@ -504,6 +509,14 @@ static Class mutableSetClass;
}
}
/* Override version from GSSet */
- (id) copyWithZone: (NSZone*)z
{
NSSet *copy = [setClass allocWithZone: z];
return [copy initWithSet: self copyItems: NO];
}
/* Designated initialiser */
- (id) initWithCapacity: (unsigned)cap
{

View file

@ -306,12 +306,16 @@ static SEL rlSel;
}
/**
* The default NSArray implemntation of a copy is simply to -retain
* the receiver and return it.
* Returns a new copy of the receiver.<br />
* The default abstract implementation of a copy is to use the
* -initWithArray:copyItems: method with the flag set to YES.<br />
* Immutable subclasses generally simply retain and return the receiver.
*/
- (id) copyWithZone: (NSZone*)zone
{
return RETAIN(self);
NSArray *copy = [NSArrayClass allocWithZone: zone];
return [copy initWithArray: self copyItems: YES];
}
/** <override-subclass />
@ -669,12 +673,16 @@ static SEL rlSel;
/**
* Returns an NSMutableArray instance containing the same objects as
* the receiver.
* the receiver.<br />
* The default implementation does this by calling the
* -initWithArray:copyItems: method on a newly created object,
* and passing it NO to tell it just to retain the items.
*/
- (id) mutableCopyWithZone: (NSZone*)zone
{
return [[GSMutableArrayClass allocWithZone: zone]
initWithArray: self];
NSMutableArray *copy = [NSMutableArrayClass allocWithZone: zone];
return [copy initWithArray: self copyItems: NO];
}
/** <override-subclass />
@ -828,7 +836,7 @@ static int compare(id elem1, id elem2, void* context)
NSMutableArray *sortedArray;
sortedArray = [[NSMutableArrayClass allocWithZone:
NSDefaultMallocZone()] initWithArray: self];
NSDefaultMallocZone()] initWithArray: self copyItems: NO];
[sortedArray sortUsingFunction: comparator context: context];
return AUTORELEASE([sortedArray makeImmutableCopyOnFail: NO]);
@ -1108,32 +1116,6 @@ static int compare(id elem1, id elem2, void* context)
return NSMutableArrayClass;
}
/* The NSCopying Protocol */
- (id) copyWithZone: (NSZone*)zone
{
/* a deep copy */
unsigned count = [self count];
id objects[count];
NSArray *newArray;
unsigned i;
[self getObjects: objects];
for (i = 0; i < count; i++)
{
objects[i] = [objects[i] copyWithZone: zone];
}
newArray = [[GSArrayClass allocWithZone: zone]
initWithObjects: objects count: count];
#if GS_WITH_GC == 0
while (i > 0)
{
[objects[--i] release];
}
#endif
return newArray;
}
/** <init />
* Initialise the array with the specified capacity ... this
* should ensure that the array can have numItems added efficiently.

View file

@ -141,15 +141,31 @@ static SEL appSel;
return nil;
}
/**
* Returns a new copy of the receiver.<br />
* The default abstract implementation of a copy is to use the
* -initWithDictionary:copyItems: method with the flag set to YES.<br />
* Immutable subclasses generally simply retain and return the receiver.
*/
- (id) copyWithZone: (NSZone*)z
{
return RETAIN(self);
NSDictionary *copy = [NSDictionaryClass allocWithZone: z];
return [copy initWithDictionary: self copyItems: NO];
}
/**
* Returns a new instance containing the same objects as
* the receiver.<br />
* The default implementation does this by calling the
* -initWithDictionary:copyItems: method on a newly created object,
* and passing it NO to tell it just to retain the items.
*/
- (id) mutableCopyWithZone: (NSZone*)z
{
return [[GSMutableDictionaryClass allocWithZone: z]
initWithDictionary: self];
NSMutableDictionary *copy = [NSMutableDictionaryClass allocWithZone: z];
return [copy initWithDictionary: self copyItems: NO];
}
- (Class) classForCoder

View file

@ -113,9 +113,17 @@ static Class NSMutableSet_concrete_class;
return NSSet_abstract_class;
}
/**
* Returns a new copy of the receiver.<br />
* The default abstract implementation of a copy is to use the
* -initWithSet:copyItems: method with the flag set to YES.<br />
* Concrete subclasses generally simply retain and return the receiver.
*/
- (id) copyWithZone: (NSZone*)z
{
return RETAIN(self);
NSSet *copy = [NSSet_concrete_class allocWithZone: z];
return [copy initWithSet: self copyItems: YES];
}
/**
@ -186,9 +194,18 @@ static Class NSMutableSet_concrete_class;
return 0;
}
/**
* Returns a new instance containing the same objects as
* the receiver.<br />
* The default implementation does this by calling the
* -initWithSet:copyItems: method on a newly created object,
* and passing it NO to tell it just to retain the items.
*/
- (id) mutableCopyWithZone: (NSZone*)z
{
return [[NSMutableSet_concrete_class allocWithZone: z] initWithSet: self];
NSMutableSet *copy = [NSMutableSet_concrete_class allocWithZone: z];
return [copy initWithSet: self copyItems: NO];
}
- (NSEnumerator*) objectEnumerator
@ -493,11 +510,6 @@ static Class NSMutableSet_concrete_class;
return NSMutableSet_concrete_class;
}
- (id) copyWithZone: (NSZone*)z
{
return [[NSSet_concrete_class allocWithZone: z] initWithSet: self];
}
/** <init />
* Initialises a newly allocated set to contain no objects but
* to have space available to hold the specified number of items.<br />