2005-02-22 11:22:44 +00:00
|
|
|
|
/** Concrete implementation of NSArray
|
1999-09-14 19:24:58 +00:00
|
|
|
|
Copyright (C) 1995, 1996, 1998, 1999 Free Software Foundation, Inc.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1999-06-29 12:42:09 +00:00
|
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
|
Date: March 1995
|
|
|
|
|
Rewrite by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1999-06-29 12:42:09 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1999-06-29 12:42:09 +00:00
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1999-06-29 12:42:09 +00:00
|
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1999-06-29 12:42:09 +00:00
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1999-06-29 12:42:09 +00:00
|
|
|
|
License along with this library; if not, write to the Free
|
2006-05-15 12:07:35 +00:00
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
Boston, MA 02111 USA.
|
2001-12-18 16:18:18 +00:00
|
|
|
|
|
|
|
|
|
$Date$ $Revision$
|
1999-06-29 12:42:09 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2010-02-19 08:12:46 +00:00
|
|
|
|
#import "common.h"
|
2007-11-29 20:53:26 +00:00
|
|
|
|
#import "Foundation/NSArray.h"
|
|
|
|
|
#import "GNUstepBase/GSObjCRuntime.h"
|
|
|
|
|
#import "Foundation/NSDictionary.h"
|
|
|
|
|
#import "Foundation/NSEnumerator.h"
|
|
|
|
|
#import "Foundation/NSException.h"
|
|
|
|
|
#import "Foundation/NSPortCoder.h"
|
|
|
|
|
#import "Foundation/NSValue.h"
|
2004-01-27 21:51:33 +00:00
|
|
|
|
// For private method _decodeArrayOfObjectsForKey:
|
2007-11-29 20:53:26 +00:00
|
|
|
|
#import "Foundation/NSKeyedArchiver.h"
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
2007-11-29 20:53:26 +00:00
|
|
|
|
#import "GSPrivate.h"
|
2012-09-19 13:31:09 +00:00
|
|
|
|
#import "GSSorting.h"
|
2006-10-26 08:33:40 +00:00
|
|
|
|
|
2000-10-30 18:00:27 +00:00
|
|
|
|
static SEL eqSel;
|
2003-02-16 11:31:28 +00:00
|
|
|
|
static SEL oaiSel;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
static Class GSArrayClass;
|
|
|
|
|
#else
|
2003-01-20 17:18:06 +00:00
|
|
|
|
static Class GSInlineArrayClass;
|
2010-01-10 14:38:16 +00:00
|
|
|
|
/* This class stores objects inline in data beyond the end of the instance.
|
|
|
|
|
* However, when GC is enabled the object data is typed, and all data after
|
|
|
|
|
* the end of the class is ignored by the garbage collector (which would
|
|
|
|
|
* mean that objects in the array could be collected).
|
2010-03-07 21:33:38 +00:00
|
|
|
|
* We therefore do not provide the class when GC is being used.
|
2010-01-10 14:38:16 +00:00
|
|
|
|
*/
|
|
|
|
|
@interface GSInlineArray : GSArray
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
@end
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#endif
|
2003-01-20 17:18:06 +00:00
|
|
|
|
|
2005-07-08 11:48:37 +00:00
|
|
|
|
@class GSArray;
|
|
|
|
|
|
|
|
|
|
@interface GSArrayEnumerator : NSEnumerator
|
|
|
|
|
{
|
|
|
|
|
GSArray *array;
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger pos;
|
2005-07-08 11:48:37 +00:00
|
|
|
|
}
|
|
|
|
|
- (id) initWithArray: (GSArray*)anArray;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@interface GSArrayEnumeratorReverse : GSArrayEnumerator
|
|
|
|
|
@end
|
|
|
|
|
|
2003-10-24 09:27:09 +00:00
|
|
|
|
@interface GSMutableArray (GSArrayBehavior)
|
2010-03-08 07:06:47 +00:00
|
|
|
|
- (void) _raiseRangeExceptionWithIndex: (NSUInteger)index from: (SEL)sel;
|
2003-10-24 09:27:09 +00:00
|
|
|
|
@end
|
|
|
|
|
|
2001-01-08 16:45:36 +00:00
|
|
|
|
@implementation GSArray
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
2010-03-08 07:06:47 +00:00
|
|
|
|
- (void) _raiseRangeExceptionWithIndex: (NSUInteger)index from: (SEL)sel
|
2003-10-24 09:27:09 +00:00
|
|
|
|
{
|
|
|
|
|
NSDictionary *info;
|
|
|
|
|
NSException *exception;
|
|
|
|
|
NSString *reason;
|
|
|
|
|
|
|
|
|
|
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
2015-01-16 15:25:50 +00:00
|
|
|
|
[NSNumber numberWithUnsignedInteger: index], @"Index",
|
|
|
|
|
[NSNumber numberWithUnsignedInteger: _count], @"Count",
|
2003-10-24 09:27:09 +00:00
|
|
|
|
self, @"Array", nil, nil];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
2009-01-13 15:57:38 +00:00
|
|
|
|
reason = [NSString stringWithFormat:
|
2013-07-03 06:46:41 +00:00
|
|
|
|
@"Index %"PRIuPTR" is out of range %d (in '%@')",
|
2003-10-24 09:27:09 +00:00
|
|
|
|
index, _count, NSStringFromSelector(sel)];
|
|
|
|
|
|
|
|
|
|
exception = [NSException exceptionWithName: NSRangeException
|
|
|
|
|
reason: reason
|
|
|
|
|
userInfo: info];
|
|
|
|
|
[exception raise];
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-29 12:42:09 +00:00
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
2001-01-08 16:45:36 +00:00
|
|
|
|
if (self == [GSArray class])
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
[self setVersion: 1];
|
2000-10-30 18:00:27 +00:00
|
|
|
|
eqSel = @selector(isEqual:);
|
2003-02-16 11:31:28 +00:00
|
|
|
|
oaiSel = @selector(objectAtIndex:);
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
GSArrayClass = [GSArray class];
|
|
|
|
|
#else
|
2003-01-20 17:18:06 +00:00
|
|
|
|
GSInlineArrayClass = [GSInlineArray class];
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#endif
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (id) allocWithZone: (NSZone*)zone
|
|
|
|
|
{
|
2010-03-07 21:33:38 +00:00
|
|
|
|
GSArray *array = (GSArray*)NSAllocateObject(self, 0, zone);
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
2006-05-15 12:07:35 +00:00
|
|
|
|
return (id)array;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-20 17:18:06 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
|
|
|
|
{
|
|
|
|
|
return RETAIN(self); // Optimised version
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-29 12:42:09 +00:00
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
if (_contents_array)
|
|
|
|
|
{
|
1999-07-03 19:59:44 +00:00
|
|
|
|
#if !GS_WITH_GC
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < _count; i++)
|
|
|
|
|
{
|
|
|
|
|
[_contents_array[i] release];
|
|
|
|
|
}
|
1999-07-03 19:59:44 +00:00
|
|
|
|
#endif
|
1999-06-29 12:42:09 +00:00
|
|
|
|
NSZoneFree([self zone], _contents_array);
|
2009-10-10 08:16:17 +00:00
|
|
|
|
_contents_array = 0;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
2009-10-10 08:16:17 +00:00
|
|
|
|
[super dealloc];
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-07 09:22:10 +00:00
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
return [self initWithObjects: 0 count: 0];
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-29 12:42:09 +00:00
|
|
|
|
/* This is the designated initializer for NSArray. */
|
2011-07-22 16:07:23 +00:00
|
|
|
|
- (id) initWithObjects: (const id[])objects count: (NSUInteger)count
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
2009-01-19 11:00:33 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
_contents_array = NSAllocateCollectable(sizeof(id)*count,
|
|
|
|
|
NSScannedOption);
|
|
|
|
|
#else
|
1999-06-29 12:42:09 +00:00
|
|
|
|
_contents_array = NSZoneMalloc([self zone], sizeof(id)*count);
|
2009-01-19 11:00:33 +00:00
|
|
|
|
#endif
|
1999-06-29 12:42:09 +00:00
|
|
|
|
if (_contents_array == 0)
|
|
|
|
|
{
|
2010-02-25 18:49:31 +00:00
|
|
|
|
DESTROY(self);
|
1999-06-29 12:42:09 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
1999-07-03 19:59:44 +00:00
|
|
|
|
if ((_contents_array[i] = RETAIN(objects[i])) == nil)
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
_count = i;
|
2010-02-25 18:49:31 +00:00
|
|
|
|
DESTROY(self);
|
1999-06-29 12:42:09 +00:00
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
2003-10-24 06:53:53 +00:00
|
|
|
|
format: @"Tried to init array with nil to object"];
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_count = count;
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
2004-01-28 07:33:20 +00:00
|
|
|
|
if ([aCoder allowsKeyedCoding])
|
|
|
|
|
{
|
|
|
|
|
[super encodeWithCoder: aCoder];
|
|
|
|
|
}
|
|
|
|
|
else
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
2004-01-28 07:33:20 +00:00
|
|
|
|
/* For performace we encode directly ... must exactly match the
|
|
|
|
|
* superclass implemenation. */
|
2010-03-08 12:07:11 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(unsigned)
|
2004-01-28 07:33:20 +00:00
|
|
|
|
at: &_count];
|
|
|
|
|
if (_count > 0)
|
|
|
|
|
{
|
|
|
|
|
[aCoder encodeArrayOfObjCType: @encode(id)
|
|
|
|
|
count: _count
|
|
|
|
|
at: _contents_array];
|
|
|
|
|
}
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
2004-01-27 21:51:33 +00:00
|
|
|
|
if ([aCoder allowsKeyedCoding])
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
2004-01-28 07:33:20 +00:00
|
|
|
|
self = [super initWithCoder: aCoder];
|
2004-01-27 21:51:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-01-28 07:33:20 +00:00
|
|
|
|
/* for performance, we decode directly into memory rather than
|
|
|
|
|
* using the superclass method. Must exactly match superclass. */
|
2010-03-08 12:07:11 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned)
|
2004-01-28 07:33:20 +00:00
|
|
|
|
at: &_count];
|
|
|
|
|
if (_count > 0)
|
|
|
|
|
{
|
2009-01-19 11:00:33 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
_contents_array = NSAllocateCollectable(sizeof(id) * _count,
|
|
|
|
|
NSScannedOption);
|
|
|
|
|
#else
|
2004-01-28 07:33:20 +00:00
|
|
|
|
_contents_array = NSZoneCalloc([self zone], _count, sizeof(id));
|
2009-01-19 11:00:33 +00:00
|
|
|
|
#endif
|
2004-01-28 07:33:20 +00:00
|
|
|
|
if (_contents_array == 0)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSMallocException
|
|
|
|
|
format: @"Unable to make array"];
|
|
|
|
|
}
|
|
|
|
|
[aCoder decodeArrayOfObjCType: @encode(id)
|
|
|
|
|
count: _count
|
|
|
|
|
at: _contents_array];
|
|
|
|
|
}
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (NSUInteger) count
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
return _count;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (NSUInteger) hash
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
return _count;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (NSUInteger) indexOfObject: anObject
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (anObject == nil)
|
|
|
|
|
return NSNotFound;
|
|
|
|
|
/*
|
|
|
|
|
* For large arrays, speed things up a little by caching the method.
|
|
|
|
|
*/
|
|
|
|
|
if (_count > 1)
|
|
|
|
|
{
|
|
|
|
|
BOOL (*imp)(id,SEL,id);
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
imp = (BOOL (*)(id,SEL,id))[anObject methodForSelector: eqSel];
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < _count; i++)
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if ((*imp)(anObject, eqSel, _contents_array[i]))
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (_count == 1 && [anObject isEqual: _contents_array[0]])
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return NSNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (NSUInteger) indexOfObjectIdenticalTo: anObject
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < _count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (anObject == _contents_array[i])
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NSNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-16 11:31:28 +00:00
|
|
|
|
- (BOOL) isEqualToArray: (NSArray*)otherArray
|
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
2003-02-16 11:31:28 +00:00
|
|
|
|
if (self == (id)otherArray)
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
if (_count != [otherArray count])
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
if (_count > 0)
|
|
|
|
|
{
|
|
|
|
|
IMP get1 = [otherArray methodForSelector: oaiSel];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < _count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (![_contents_array[i] isEqual: (*get1)(otherArray, oaiSel, i)])
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-29 12:42:09 +00:00
|
|
|
|
- (id) lastObject
|
|
|
|
|
{
|
|
|
|
|
if (_count)
|
|
|
|
|
{
|
|
|
|
|
return _contents_array[_count-1];
|
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (id) objectAtIndex: (NSUInteger)index
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (index >= _count)
|
|
|
|
|
{
|
2003-10-24 06:53:53 +00:00
|
|
|
|
[self _raiseRangeExceptionWithIndex: index from: _cmd];
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
return _contents_array[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) makeObjectsPerformSelector: (SEL)aSelector
|
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
2004-09-24 15:57:54 +00:00
|
|
|
|
for (i = 0; i < _count; i++)
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
[_contents_array[i] performSelector: aSelector];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject: (id)argument
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
2004-09-24 15:57:54 +00:00
|
|
|
|
for (i = 0; i < _count; i++)
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
[_contents_array[i] performSelector: aSelector withObject: argument];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-24 13:09:22 +00:00
|
|
|
|
- (void) getObjects: (__unsafe_unretained id[])aBuffer
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < _count; i++)
|
|
|
|
|
{
|
|
|
|
|
aBuffer[i] = _contents_array[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-24 13:09:22 +00:00
|
|
|
|
- (void) getObjects: (__unsafe_unretained id[])aBuffer range: (NSRange)aRange
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i, j = 0, e = aRange.location + aRange.length;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
|
|
|
|
GS_RANGE_CHECK(aRange, _count);
|
|
|
|
|
|
|
|
|
|
for (i = aRange.location; i < e; i++)
|
|
|
|
|
{
|
|
|
|
|
aBuffer[j++] = _contents_array[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-28 13:31:00 +00:00
|
|
|
|
|
2012-09-19 13:31:09 +00:00
|
|
|
|
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
|
2011-07-24 13:09:22 +00:00
|
|
|
|
objects: (__unsafe_unretained id[])stackbuf
|
2009-01-28 13:31:00 +00:00
|
|
|
|
count: (NSUInteger)len
|
|
|
|
|
{
|
|
|
|
|
/* For immutable arrays we can return the contents pointer directly. */
|
2009-02-04 05:30:39 +00:00
|
|
|
|
NSUInteger count = _count - state->state;
|
|
|
|
|
state->mutationsPtr = (unsigned long *)self;
|
|
|
|
|
state->itemsPtr = _contents_array + state->state;
|
|
|
|
|
state->state += count;
|
|
|
|
|
return count;
|
2009-01-28 13:31:00 +00:00
|
|
|
|
}
|
1999-06-29 12:42:09 +00:00
|
|
|
|
@end
|
|
|
|
|
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#if !GS_WITH_GC
|
2001-01-08 16:45:36 +00:00
|
|
|
|
@implementation GSInlineArray
|
2000-10-30 18:00:27 +00:00
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
if (_contents_array)
|
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
2000-10-30 18:00:27 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < _count; i++)
|
|
|
|
|
{
|
|
|
|
|
[_contents_array[i] release];
|
|
|
|
|
}
|
2009-10-10 08:16:17 +00:00
|
|
|
|
_contents_array = 0;
|
2000-10-30 18:00:27 +00:00
|
|
|
|
}
|
2009-10-10 08:16:17 +00:00
|
|
|
|
[super dealloc];
|
2000-10-30 18:00:27 +00:00
|
|
|
|
}
|
2004-09-07 09:22:10 +00:00
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
return [self initWithObjects: 0 count: 0];
|
|
|
|
|
}
|
2011-07-22 16:07:23 +00:00
|
|
|
|
- (id) initWithObjects: (const id[])objects count: (NSUInteger)count
|
2000-10-30 18:00:27 +00:00
|
|
|
|
{
|
2010-02-14 10:48:10 +00:00
|
|
|
|
_contents_array
|
|
|
|
|
= (id*)(((void*)self) + class_getInstanceSize([self class]));
|
|
|
|
|
|
2000-10-30 18:00:27 +00:00
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
2000-10-30 18:00:27 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
if ((_contents_array[i] = RETAIN(objects[i])) == nil)
|
|
|
|
|
{
|
|
|
|
|
_count = i;
|
2010-02-25 18:49:31 +00:00
|
|
|
|
DESTROY(self);
|
2000-10-30 18:00:27 +00:00
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
2003-10-24 06:53:53 +00:00
|
|
|
|
format: @"Tried to init array with nil object"];
|
2000-10-30 18:00:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_count = count;
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
@end
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#endif
|
2000-10-30 18:00:27 +00:00
|
|
|
|
|
2001-01-08 16:45:36 +00:00
|
|
|
|
@implementation GSMutableArray
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
2001-01-08 16:45:36 +00:00
|
|
|
|
if (self == [GSMutableArray class])
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
[self setVersion: 1];
|
2002-11-27 12:52:29 +00:00
|
|
|
|
GSObjCAddClassBehavior(self, [GSArray class]);
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-27 11:09:12 +00:00
|
|
|
|
- (void) addObject: (id)anObject
|
|
|
|
|
{
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
2002-08-27 11:09:12 +00:00
|
|
|
|
if (anObject == nil)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
|
format: @"Tried to add nil to array"];
|
|
|
|
|
}
|
|
|
|
|
if (_count >= _capacity)
|
|
|
|
|
{
|
|
|
|
|
id *ptr;
|
|
|
|
|
size_t size = (_capacity + _grow_factor)*sizeof(id);
|
|
|
|
|
|
|
|
|
|
ptr = NSZoneRealloc([self zone], _contents_array, size);
|
|
|
|
|
if (ptr == 0)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSMallocException
|
2003-10-24 06:53:53 +00:00
|
|
|
|
format: @"Unable to grow array"];
|
2002-08-27 11:09:12 +00:00
|
|
|
|
}
|
|
|
|
|
_contents_array = ptr;
|
|
|
|
|
_capacity += _grow_factor;
|
|
|
|
|
_grow_factor = _capacity/2;
|
|
|
|
|
}
|
|
|
|
|
_contents_array[_count] = RETAIN(anObject);
|
|
|
|
|
_count++; /* Do this AFTER we have retained the object. */
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
2002-08-27 11:09:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-20 17:18:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* Optimised code for copying
|
|
|
|
|
*/
|
|
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
|
|
|
|
{
|
|
|
|
|
NSArray *copy;
|
|
|
|
|
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
copy = (id)NSAllocateObject(GSArrayClass, 0, zone);
|
|
|
|
|
#else
|
2003-01-20 17:18:06 +00:00
|
|
|
|
copy = (id)NSAllocateObject(GSInlineArrayClass, sizeof(id)*_count, zone);
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#endif
|
2003-01-20 17:18:06 +00:00
|
|
|
|
return [copy initWithObjects: _contents_array count: _count];
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (void) exchangeObjectAtIndex: (NSUInteger)i1
|
|
|
|
|
withObjectAtIndex: (NSUInteger)i2
|
2002-08-27 11:09:12 +00:00
|
|
|
|
{
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
2002-08-27 11:09:12 +00:00
|
|
|
|
if (i1 >= _count)
|
|
|
|
|
{
|
2003-10-24 06:53:53 +00:00
|
|
|
|
[self _raiseRangeExceptionWithIndex: i1 from: _cmd];
|
2002-08-27 11:09:12 +00:00
|
|
|
|
}
|
|
|
|
|
if (i2 >= _count)
|
|
|
|
|
{
|
2003-10-24 06:53:53 +00:00
|
|
|
|
[self _raiseRangeExceptionWithIndex: i2 from: _cmd];
|
2002-08-27 11:09:12 +00:00
|
|
|
|
}
|
|
|
|
|
if (i1 != i2)
|
|
|
|
|
{
|
|
|
|
|
id tmp = _contents_array[i1];
|
|
|
|
|
|
|
|
|
|
_contents_array[i1] = _contents_array[i2];
|
|
|
|
|
_contents_array[i2] = tmp;
|
|
|
|
|
}
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
2002-08-27 11:09:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-07 09:22:10 +00:00
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
return [self initWithCapacity: 0];
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (id) initWithCapacity: (NSUInteger)cap
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (cap == 0)
|
|
|
|
|
{
|
|
|
|
|
cap = 1;
|
|
|
|
|
}
|
2009-01-19 11:00:33 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
_contents_array = NSAllocateCollectable(sizeof(id)*cap, NSScannedOption);
|
|
|
|
|
#else
|
1999-06-29 12:42:09 +00:00
|
|
|
|
_contents_array = NSZoneMalloc([self zone], sizeof(id)*cap);
|
2009-01-19 11:00:33 +00:00
|
|
|
|
#endif
|
1999-06-29 12:42:09 +00:00
|
|
|
|
_capacity = cap;
|
|
|
|
|
_grow_factor = cap > 1 ? cap/2 : 1;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
2004-01-27 21:51:33 +00:00
|
|
|
|
if ([aCoder allowsKeyedCoding])
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
2011-05-12 08:24:15 +00:00
|
|
|
|
self = [super initWithCoder: aCoder];
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
2004-01-27 21:51:33 +00:00
|
|
|
|
else
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
2010-03-08 12:07:11 +00:00
|
|
|
|
unsigned count;
|
2004-01-27 21:51:33 +00:00
|
|
|
|
|
2010-03-08 12:07:11 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned)
|
2004-01-27 21:51:33 +00:00
|
|
|
|
at: &count];
|
|
|
|
|
if ((self = [self initWithCapacity: count]) == nil)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSMallocException
|
|
|
|
|
format: @"Unable to make array while initializing from coder"];
|
|
|
|
|
}
|
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
[aCoder decodeArrayOfObjCType: @encode(id)
|
|
|
|
|
count: count
|
|
|
|
|
at: _contents_array];
|
|
|
|
|
_count = count;
|
|
|
|
|
}
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-22 16:07:23 +00:00
|
|
|
|
- (id) initWithObjects: (const id[])objects count: (NSUInteger)count
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
self = [self initWithCapacity: count];
|
|
|
|
|
if (self != nil && count > 0)
|
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger i;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
1999-07-03 19:59:44 +00:00
|
|
|
|
if ((_contents_array[i] = RETAIN(objects[i])) == nil)
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
_count = i;
|
2010-02-25 18:49:31 +00:00
|
|
|
|
DESTROY(self);
|
1999-06-29 12:42:09 +00:00
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
2003-10-24 06:53:53 +00:00
|
|
|
|
format: @"Tried to init array with nil object"];
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_count = count;
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (void) insertObject: (id)anObject atIndex: (NSUInteger)index
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
if (!anObject)
|
|
|
|
|
{
|
2003-10-24 06:53:53 +00:00
|
|
|
|
NSException *exception;
|
|
|
|
|
NSDictionary *info;
|
|
|
|
|
|
|
|
|
|
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
2015-01-16 15:25:50 +00:00
|
|
|
|
[NSNumber numberWithUnsignedInteger: index], @"Index",
|
2003-10-24 06:53:53 +00:00
|
|
|
|
self, @"Array", nil, nil];
|
|
|
|
|
|
|
|
|
|
exception = [NSException exceptionWithName: NSInvalidArgumentException
|
|
|
|
|
reason: @"Tried to insert nil to array"
|
|
|
|
|
userInfo: info];
|
|
|
|
|
[exception raise];
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (index > _count)
|
|
|
|
|
{
|
2003-10-24 06:53:53 +00:00
|
|
|
|
[self _raiseRangeExceptionWithIndex: index from: _cmd];
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (_count == _capacity)
|
|
|
|
|
{
|
|
|
|
|
id *ptr;
|
|
|
|
|
size_t size = (_capacity + _grow_factor)*sizeof(id);
|
|
|
|
|
|
|
|
|
|
ptr = NSZoneRealloc([self zone], _contents_array, size);
|
|
|
|
|
if (ptr == 0)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSMallocException
|
|
|
|
|
format: @"Unable to grow"];
|
|
|
|
|
}
|
|
|
|
|
_contents_array = ptr;
|
|
|
|
|
_capacity += _grow_factor;
|
|
|
|
|
_grow_factor = _capacity/2;
|
|
|
|
|
}
|
2009-01-28 23:43:05 +00:00
|
|
|
|
memmove(&_contents_array[index+1], &_contents_array[index],
|
|
|
|
|
(_count - index) * sizeof(id));
|
1999-06-29 12:42:09 +00:00
|
|
|
|
/*
|
|
|
|
|
* Make sure the array is 'sane' so that it can be deallocated
|
|
|
|
|
* safely by an autorelease pool if the '[anObject retain]' causes
|
|
|
|
|
* an exception.
|
|
|
|
|
*/
|
|
|
|
|
_contents_array[index] = nil;
|
|
|
|
|
_count++;
|
1999-07-03 19:59:44 +00:00
|
|
|
|
_contents_array[index] = RETAIN(anObject);
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-14 08:52:39 +00:00
|
|
|
|
- (id) makeImmutableCopyOnFail: (BOOL)force
|
|
|
|
|
{
|
2011-02-20 16:21:43 +00:00
|
|
|
|
GSClassSwizzle(self, [GSArray class]);
|
2002-10-14 08:52:39 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-05 16:01:21 +00:00
|
|
|
|
- (void) removeAllObjects
|
|
|
|
|
{
|
|
|
|
|
NSUInteger pos;
|
|
|
|
|
|
|
|
|
|
if ((pos = _count) > 0)
|
|
|
|
|
{
|
|
|
|
|
#if GS_WITH_GC == 0
|
|
|
|
|
IMP rel = 0;
|
|
|
|
|
Class last = Nil;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
_version++;
|
|
|
|
|
_count = 0;
|
|
|
|
|
while (pos-- > 0)
|
|
|
|
|
{
|
|
|
|
|
#if GS_WITH_GC == 0
|
|
|
|
|
id o = _contents_array[pos];
|
|
|
|
|
Class c = object_getClass(o);
|
|
|
|
|
|
|
|
|
|
if (c != last)
|
|
|
|
|
{
|
|
|
|
|
last = c;
|
|
|
|
|
rel = [o methodForSelector: @selector(release)];
|
|
|
|
|
}
|
|
|
|
|
(*rel)(o, @selector(release));
|
|
|
|
|
#endif
|
|
|
|
|
_contents_array[pos] = nil;
|
|
|
|
|
}
|
|
|
|
|
_version++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-29 12:42:09 +00:00
|
|
|
|
- (void) removeLastObject
|
|
|
|
|
{
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
if (_count == 0)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSRangeException
|
|
|
|
|
format: @"Trying to remove from an empty array."];
|
|
|
|
|
}
|
|
|
|
|
_count--;
|
1999-07-03 19:59:44 +00:00
|
|
|
|
RELEASE(_contents_array[_count]);
|
2002-05-28 05:23:36 +00:00
|
|
|
|
_contents_array[_count] = 0;
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (void) removeObject: (id)anObject
|
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger index;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-11-04 10:42:20 +00:00
|
|
|
|
if (anObject == nil)
|
|
|
|
|
{
|
2001-05-22 09:30:07 +00:00
|
|
|
|
NSWarnMLog(@"attempt to remove nil object");
|
1999-11-04 10:42:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
index = _count;
|
|
|
|
|
if (index > 0)
|
1999-09-14 19:24:58 +00:00
|
|
|
|
{
|
1999-12-13 12:14:01 +00:00
|
|
|
|
BOOL (*imp)(id,SEL,id);
|
|
|
|
|
#if GS_WITH_GC == 0
|
|
|
|
|
BOOL retained = NO;
|
|
|
|
|
#endif
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
|
|
|
|
imp = (BOOL (*)(id,SEL,id))[anObject methodForSelector: eqSel];
|
|
|
|
|
while (index-- > 0)
|
|
|
|
|
{
|
|
|
|
|
if ((*imp)(anObject, eqSel, _contents_array[index]) == YES)
|
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger pos = index;
|
1999-09-28 19:35:09 +00:00
|
|
|
|
#if GS_WITH_GC == 0
|
1999-09-14 19:24:58 +00:00
|
|
|
|
id obj = _contents_array[index];
|
1999-12-13 12:14:01 +00:00
|
|
|
|
|
|
|
|
|
if (retained == NO)
|
|
|
|
|
{
|
|
|
|
|
RETAIN(anObject);
|
|
|
|
|
retained = YES;
|
|
|
|
|
}
|
1999-09-28 19:35:09 +00:00
|
|
|
|
#endif
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
|
|
|
|
while (++pos < _count)
|
|
|
|
|
{
|
|
|
|
|
_contents_array[pos-1] = _contents_array[pos];
|
|
|
|
|
}
|
|
|
|
|
_count--;
|
2003-10-14 09:00:42 +00:00
|
|
|
|
_contents_array[_count] = 0;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
RELEASE(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-12-13 12:14:01 +00:00
|
|
|
|
#if GS_WITH_GC == 0
|
|
|
|
|
if (retained == YES)
|
|
|
|
|
{
|
|
|
|
|
RELEASE(anObject);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1999-09-14 19:24:58 +00:00
|
|
|
|
}
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (void) removeObjectAtIndex: (NSUInteger)index
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
id obj;
|
|
|
|
|
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
if (index >= _count)
|
|
|
|
|
{
|
2003-10-24 06:53:53 +00:00
|
|
|
|
[self _raiseRangeExceptionWithIndex: index from: _cmd];
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
obj = _contents_array[index];
|
|
|
|
|
_count--;
|
|
|
|
|
while (index < _count)
|
|
|
|
|
{
|
|
|
|
|
_contents_array[index] = _contents_array[index+1];
|
|
|
|
|
index++;
|
|
|
|
|
}
|
2002-05-28 05:23:36 +00:00
|
|
|
|
_contents_array[_count] = 0;
|
2011-02-28 19:49:57 +00:00
|
|
|
|
[obj release]; /* Adjust array BEFORE releasing object. */
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (void) removeObjectIdenticalTo: (id)anObject
|
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger index;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-11-04 10:42:20 +00:00
|
|
|
|
if (anObject == nil)
|
|
|
|
|
{
|
2001-05-22 09:30:07 +00:00
|
|
|
|
NSWarnMLog(@"attempt to remove nil object");
|
1999-11-04 10:42:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
index = _count;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
while (index-- > 0)
|
|
|
|
|
{
|
|
|
|
|
if (_contents_array[index] == anObject)
|
|
|
|
|
{
|
1999-09-28 19:35:09 +00:00
|
|
|
|
#if GS_WITH_GC == 0
|
1999-09-14 19:24:58 +00:00
|
|
|
|
id obj = _contents_array[index];
|
1999-09-28 19:35:09 +00:00
|
|
|
|
#endif
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger pos = index;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
|
|
|
|
while (++pos < _count)
|
|
|
|
|
{
|
|
|
|
|
_contents_array[pos-1] = _contents_array[pos];
|
|
|
|
|
}
|
|
|
|
|
_count--;
|
2002-05-28 05:23:36 +00:00
|
|
|
|
_contents_array[_count] = 0;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
RELEASE(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 10:42:00 +00:00
|
|
|
|
- (void) removeObjectsInRange: (NSRange)aRange
|
|
|
|
|
{
|
|
|
|
|
GS_RANGE_CHECK(aRange, _count);
|
|
|
|
|
|
|
|
|
|
if (aRange.length > 0)
|
|
|
|
|
{
|
|
|
|
|
NSUInteger index;
|
|
|
|
|
NSUInteger tail;
|
|
|
|
|
NSUInteger end;
|
|
|
|
|
#if GS_WITH_GC == 0
|
|
|
|
|
IMP rel = 0;
|
|
|
|
|
Class last = Nil;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
_version++;
|
|
|
|
|
index = aRange.location;
|
|
|
|
|
|
|
|
|
|
#if GS_WITH_GC == 0
|
|
|
|
|
/* Release all the objects we are removing.
|
|
|
|
|
*/
|
|
|
|
|
end = NSMaxRange(aRange);
|
|
|
|
|
while (end-- > index)
|
|
|
|
|
{
|
|
|
|
|
id o = _contents_array[end];
|
|
|
|
|
Class c = object_getClass(o);
|
|
|
|
|
|
|
|
|
|
if (c != last)
|
|
|
|
|
{
|
|
|
|
|
last = c;
|
|
|
|
|
rel = [o methodForSelector: @selector(release)];
|
|
|
|
|
}
|
|
|
|
|
(*rel)(o, @selector(release));
|
|
|
|
|
_contents_array[end] = nil;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
/* Move any trailing objects to fill the hole we made.
|
|
|
|
|
*/
|
|
|
|
|
end = NSMaxRange(aRange);
|
|
|
|
|
tail = _count - end;
|
|
|
|
|
if (tail > 0)
|
|
|
|
|
{
|
|
|
|
|
memmove(_contents_array + index, _contents_array + end,
|
|
|
|
|
tail * sizeof(id));
|
|
|
|
|
index += tail;
|
|
|
|
|
}
|
|
|
|
|
_count = index;
|
|
|
|
|
|
|
|
|
|
/* Clear emptied part of buffer.
|
|
|
|
|
*/
|
|
|
|
|
memset(_contents_array + _count, 0, aRange.length * sizeof(id));
|
|
|
|
|
_version++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 07:06:47 +00:00
|
|
|
|
- (void) replaceObjectAtIndex: (NSUInteger)index withObject: (id)anObject
|
1999-06-29 12:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
id obj;
|
|
|
|
|
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
if (index >= _count)
|
|
|
|
|
{
|
2003-10-24 09:27:09 +00:00
|
|
|
|
[self _raiseRangeExceptionWithIndex: index from: _cmd];
|
1999-07-03 19:59:44 +00:00
|
|
|
|
}
|
2008-05-14 09:31:33 +00:00
|
|
|
|
if (!anObject)
|
|
|
|
|
{
|
|
|
|
|
NSException *exception;
|
|
|
|
|
NSDictionary *info;
|
|
|
|
|
|
|
|
|
|
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
2015-01-16 15:25:50 +00:00
|
|
|
|
[NSNumber numberWithUnsignedInteger: index], @"Index",
|
2013-05-01 14:24:14 +00:00
|
|
|
|
_contents_array[index], @"OldObject",
|
2008-05-14 09:31:33 +00:00
|
|
|
|
self, @"Array", nil, nil];
|
|
|
|
|
|
|
|
|
|
exception = [NSException exceptionWithName: NSInvalidArgumentException
|
|
|
|
|
reason: @"Tried to replace object in array with nil"
|
|
|
|
|
userInfo: info];
|
|
|
|
|
[exception raise];
|
|
|
|
|
}
|
1999-06-29 12:42:09 +00:00
|
|
|
|
/*
|
|
|
|
|
* Swap objects in order so that there is always a valid object in the
|
|
|
|
|
* array in case a retain or release causes an exception.
|
|
|
|
|
*/
|
|
|
|
|
obj = _contents_array[index];
|
2011-02-28 19:49:57 +00:00
|
|
|
|
[anObject retain];
|
1999-06-29 12:42:09 +00:00
|
|
|
|
_contents_array[index] = anObject;
|
2011-02-28 19:49:57 +00:00
|
|
|
|
[obj release];
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 13:31:09 +00:00
|
|
|
|
- (void) sortUsingFunction: (NSComparisonResult (*)(id,id,void*))compare
|
1999-06-29 12:42:09 +00:00
|
|
|
|
context: (void*)context
|
|
|
|
|
{
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
2012-09-19 13:31:09 +00:00
|
|
|
|
if ((1 < _count) && (NULL != compare))
|
2012-09-19 14:20:01 +00:00
|
|
|
|
{
|
|
|
|
|
GSSortUnstable(_contents_array, NSMakeRange(0,_count), (id)compare,
|
|
|
|
|
GSComparisonTypeFunction, context);
|
|
|
|
|
}
|
2012-09-19 13:31:09 +00:00
|
|
|
|
_version++;
|
|
|
|
|
}
|
1999-12-01 19:36:20 +00:00
|
|
|
|
|
2012-09-19 13:31:09 +00:00
|
|
|
|
- (void) sortWithOptions: (NSSortOptions)options
|
|
|
|
|
usingComparator: (NSComparator)comparator
|
|
|
|
|
{
|
|
|
|
|
_version++;
|
|
|
|
|
if ((1 < _count) && (NULL != comparator))
|
1999-12-01 19:36:20 +00:00
|
|
|
|
{
|
2012-09-19 14:20:01 +00:00
|
|
|
|
if (options & NSSortStable)
|
|
|
|
|
{
|
|
|
|
|
if (options & NSSortConcurrent)
|
|
|
|
|
{
|
|
|
|
|
GSSortStableConcurrent(_contents_array, NSMakeRange(0,_count),
|
|
|
|
|
(id)comparator, GSComparisonTypeComparatorBlock, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GSSortStable(_contents_array, NSMakeRange(0,_count),
|
|
|
|
|
(id)comparator, GSComparisonTypeComparatorBlock, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-19 13:31:09 +00:00
|
|
|
|
else
|
2012-09-19 14:20:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (options & NSSortConcurrent)
|
|
|
|
|
{
|
|
|
|
|
GSSortUnstableConcurrent(_contents_array, NSMakeRange(0,_count),
|
|
|
|
|
(id)comparator, GSComparisonTypeComparatorBlock, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GSSortUnstable(_contents_array, NSMakeRange(0,_count),
|
|
|
|
|
(id)comparator, GSComparisonTypeComparatorBlock, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-12-01 19:36:20 +00:00
|
|
|
|
}
|
2009-01-28 13:31:00 +00:00
|
|
|
|
_version++;
|
1999-06-29 12:42:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (NSEnumerator*) objectEnumerator
|
|
|
|
|
{
|
2005-07-08 11:48:37 +00:00
|
|
|
|
GSArrayEnumerator *enumerator;
|
|
|
|
|
|
|
|
|
|
enumerator = [GSArrayEnumerator allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
return AUTORELEASE([enumerator initWithArray: (GSArray*)self]);
|
1999-09-14 19:24:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSEnumerator*) reverseObjectEnumerator
|
|
|
|
|
{
|
2005-07-08 11:48:37 +00:00
|
|
|
|
GSArrayEnumeratorReverse *enumerator;
|
|
|
|
|
|
|
|
|
|
enumerator = [GSArrayEnumeratorReverse allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
return AUTORELEASE([enumerator initWithArray: (GSArray*)self]);
|
1999-09-14 19:24:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 13:31:09 +00:00
|
|
|
|
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
|
2011-07-24 13:09:22 +00:00
|
|
|
|
objects: (__unsafe_unretained id[])stackbuf
|
2009-01-28 13:31:00 +00:00
|
|
|
|
count: (NSUInteger)len
|
|
|
|
|
{
|
|
|
|
|
NSInteger count;
|
|
|
|
|
|
|
|
|
|
/* This is cached in the caller at the start and compared at each
|
|
|
|
|
* iteration. If it changes during the iteration then
|
|
|
|
|
* objc_enumerationMutation() will be called, throwing an exception.
|
|
|
|
|
*/
|
2011-08-16 16:04:43 +00:00
|
|
|
|
state->mutationsPtr = &_version;
|
2009-01-28 13:31:00 +00:00
|
|
|
|
count = MIN(len, _count - state->state);
|
|
|
|
|
/* If a mutation has occurred then it's possible that we are being asked to
|
|
|
|
|
* get objects from after the end of the array. Don't pass negative values
|
|
|
|
|
* to memcpy.
|
|
|
|
|
*/
|
2009-04-19 10:03:18 +00:00
|
|
|
|
if (count > 0)
|
2009-01-28 13:31:00 +00:00
|
|
|
|
{
|
2009-02-04 05:30:39 +00:00
|
|
|
|
memcpy(stackbuf, _contents_array + state->state, count * sizeof(id));
|
2009-01-28 13:31:00 +00:00
|
|
|
|
state->state += count;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
count = 0;
|
|
|
|
|
}
|
|
|
|
|
state->itemsPtr = stackbuf;
|
|
|
|
|
return count;
|
|
|
|
|
}
|
1999-09-14 19:24:58 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-01-08 16:45:36 +00:00
|
|
|
|
@implementation GSArrayEnumerator
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
2001-01-08 16:45:36 +00:00
|
|
|
|
- (id) initWithArray: (GSArray*)anArray
|
1999-09-14 19:24:58 +00:00
|
|
|
|
{
|
2009-10-10 08:16:17 +00:00
|
|
|
|
if ((self = [super init]) != nil)
|
|
|
|
|
{
|
|
|
|
|
array = anArray;
|
|
|
|
|
IF_NO_GC(RETAIN(array));
|
|
|
|
|
pos = 0;
|
|
|
|
|
}
|
1999-09-14 19:24:58 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) nextObject
|
|
|
|
|
{
|
|
|
|
|
if (pos >= array->_count)
|
|
|
|
|
return nil;
|
|
|
|
|
return array->_contents_array[pos++];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
RELEASE(array);
|
2009-10-10 08:16:17 +00:00
|
|
|
|
[super dealloc];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2001-01-08 16:45:36 +00:00
|
|
|
|
@implementation GSArrayEnumeratorReverse
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
2001-01-08 16:45:36 +00:00
|
|
|
|
- (id) initWithArray: (GSArray*)anArray
|
1999-09-14 19:24:58 +00:00
|
|
|
|
{
|
|
|
|
|
[super initWithArray: anArray];
|
|
|
|
|
pos = array->_count;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) nextObject
|
|
|
|
|
{
|
|
|
|
|
if (pos == 0)
|
|
|
|
|
return nil;
|
|
|
|
|
return array->_contents_array[--pos];
|
|
|
|
|
}
|
1999-06-29 12:42:09 +00:00
|
|
|
|
@end
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
2001-01-08 16:45:36 +00:00
|
|
|
|
@implementation GSArray (GNUstep)
|
2000-08-07 22:00:31 +00:00
|
|
|
|
/*
|
|
|
|
|
* The comparator function takes two items as arguments, the first is the
|
|
|
|
|
* item to be added, the second is the item already in the array.
|
|
|
|
|
* The function should return NSOrderedAscending if the item to be
|
|
|
|
|
* added is 'less than' the item in the array, NSOrderedDescending
|
|
|
|
|
* if it is greater, and NSOrderedSame if it is equal.
|
|
|
|
|
*/
|
2010-03-08 07:06:47 +00:00
|
|
|
|
- (NSUInteger) insertionPosition: (id)item
|
|
|
|
|
usingFunction: (NSComparisonResult (*)(id, id, void *))sorter
|
|
|
|
|
context: (void *)context
|
2000-08-07 22:00:31 +00:00
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger upper = _count;
|
|
|
|
|
NSUInteger lower = 0;
|
|
|
|
|
NSUInteger index;
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
|
|
if (item == nil)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"Attempt to find position for nil object in array"];
|
|
|
|
|
}
|
|
|
|
|
if (sorter == 0)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"Attempt to find position with null comparator"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Binary search for an item equal to the one to be inserted.
|
|
|
|
|
*/
|
|
|
|
|
for (index = upper/2; upper != lower; index = lower+(upper-lower)/2)
|
|
|
|
|
{
|
|
|
|
|
NSComparisonResult comparison;
|
|
|
|
|
|
2002-02-22 04:47:36 +00:00
|
|
|
|
comparison = (*sorter)(item, _contents_array[index], context);
|
2000-08-07 22:00:31 +00:00
|
|
|
|
if (comparison == NSOrderedAscending)
|
|
|
|
|
{
|
|
|
|
|
upper = index;
|
|
|
|
|
}
|
|
|
|
|
else if (comparison == NSOrderedDescending)
|
|
|
|
|
{
|
|
|
|
|
lower = index + 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Now skip past any equal items so the insertion point is AFTER any
|
|
|
|
|
* items that are equal to the new one.
|
|
|
|
|
*/
|
|
|
|
|
while (index < _count
|
2002-02-22 04:47:36 +00:00
|
|
|
|
&& (*sorter)(item, _contents_array[index], context) != NSOrderedAscending)
|
2000-08-07 22:00:31 +00:00
|
|
|
|
{
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 07:06:47 +00:00
|
|
|
|
- (NSUInteger) insertionPosition: (id)item
|
|
|
|
|
usingSelector: (SEL)comp
|
2000-08-07 22:00:31 +00:00
|
|
|
|
{
|
2010-03-08 07:06:47 +00:00
|
|
|
|
NSUInteger upper = _count;
|
|
|
|
|
NSUInteger lower = 0;
|
|
|
|
|
NSUInteger index;
|
2000-08-07 22:00:31 +00:00
|
|
|
|
NSComparisonResult (*imp)(id, SEL, id);
|
|
|
|
|
|
|
|
|
|
if (item == nil)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"Attempt to find position for nil object in array"];
|
|
|
|
|
}
|
|
|
|
|
if (comp == 0)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"Attempt to find position with null comparator"];
|
|
|
|
|
}
|
|
|
|
|
imp = (NSComparisonResult (*)(id, SEL, id))[item methodForSelector: comp];
|
|
|
|
|
if (imp == 0)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"Attempt to find position with unknown method"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Binary search for an item equal to the one to be inserted.
|
|
|
|
|
*/
|
|
|
|
|
for (index = upper/2; upper != lower; index = lower+(upper-lower)/2)
|
|
|
|
|
{
|
|
|
|
|
NSComparisonResult comparison;
|
|
|
|
|
|
|
|
|
|
comparison = (*imp)(item, comp, _contents_array[index]);
|
|
|
|
|
if (comparison == NSOrderedAscending)
|
|
|
|
|
{
|
|
|
|
|
upper = index;
|
|
|
|
|
}
|
|
|
|
|
else if (comparison == NSOrderedDescending)
|
|
|
|
|
{
|
|
|
|
|
lower = index + 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Now skip past any equal items so the insertion point is AFTER any
|
|
|
|
|
* items that are equal to the new one.
|
|
|
|
|
*/
|
|
|
|
|
while (index < _count
|
|
|
|
|
&& (*imp)(item, comp, _contents_array[index]) != NSOrderedAscending)
|
|
|
|
|
{
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2001-01-08 16:45:36 +00:00
|
|
|
|
@implementation GSPlaceholderArray
|
|
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
GSArrayClass = [GSArray class];
|
|
|
|
|
#else
|
2001-01-08 16:45:36 +00:00
|
|
|
|
GSInlineArrayClass = [GSInlineArray class];
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#endif
|
2001-01-08 16:45:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) autorelease
|
|
|
|
|
{
|
|
|
|
|
NSWarnLog(@"-autorelease sent to uninitialised array");
|
|
|
|
|
return self; // placeholders never get released.
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (id) objectAtIndex: (NSUInteger)index
|
2001-01-08 16:45:36 +00:00
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
2003-10-24 06:53:53 +00:00
|
|
|
|
format: @"Attempt to use uninitialised array"];
|
2001-01-08 16:45:36 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
2006-06-04 06:42:10 +00:00
|
|
|
|
GSNOSUPERDEALLOC; // placeholders never get deallocated.
|
2001-01-08 16:45:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-07 09:22:10 +00:00
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
return [self initWithObjects: 0 count: 0];
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-08 16:45:36 +00:00
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
2004-01-27 21:51:33 +00:00
|
|
|
|
if ([aCoder allowsKeyedCoding])
|
|
|
|
|
{
|
2005-02-22 11:22:44 +00:00
|
|
|
|
NSArray *array = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
|
2011-05-12 08:24:15 +00:00
|
|
|
|
@"NS.objects"];
|
|
|
|
|
if (array != nil)
|
|
|
|
|
{
|
2011-07-22 16:07:23 +00:00
|
|
|
|
return (GSPlaceholderArray*)RETAIN(array);
|
2011-05-12 08:24:15 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return [super initWithCoder: aCoder];
|
|
|
|
|
}
|
2004-01-27 21:51:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2001-01-08 16:45:36 +00:00
|
|
|
|
{
|
2010-03-08 12:07:11 +00:00
|
|
|
|
unsigned c;
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
GSArray *a;
|
|
|
|
|
|
2010-03-08 12:07:11 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &c];
|
2010-03-05 09:30:18 +00:00
|
|
|
|
a = (id)NSAllocateObject(GSArrayClass, 0, [self zone]);
|
2009-01-19 11:00:33 +00:00
|
|
|
|
a->_contents_array = NSAllocateCollectable(sizeof(id)*c, NSScannedOption);
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#else
|
|
|
|
|
GSInlineArray *a;
|
2004-01-27 21:51:33 +00:00
|
|
|
|
|
2010-03-08 12:07:11 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &c];
|
2006-08-13 11:25:13 +00:00
|
|
|
|
a = (id)NSAllocateObject(GSInlineArrayClass,
|
2010-03-05 09:30:18 +00:00
|
|
|
|
sizeof(id)*c, [self zone]);
|
2010-02-14 10:48:10 +00:00
|
|
|
|
a->_contents_array
|
|
|
|
|
= (id*)(((void*)a) + class_getInstanceSize([a class]));
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#endif
|
2004-01-27 21:51:33 +00:00
|
|
|
|
if (c > 0)
|
|
|
|
|
{
|
|
|
|
|
[aCoder decodeArrayOfObjCType: @encode(id)
|
|
|
|
|
count: c
|
|
|
|
|
at: a->_contents_array];
|
|
|
|
|
}
|
|
|
|
|
a->_count = c;
|
2011-07-22 16:07:23 +00:00
|
|
|
|
return (GSPlaceholderArray*)a;
|
2001-01-08 16:45:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-22 16:07:23 +00:00
|
|
|
|
- (id) initWithObjects: (const id[])objects count: (NSUInteger)count
|
2001-01-08 16:45:36 +00:00
|
|
|
|
{
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#if GS_WITH_GC
|
2010-03-05 09:30:18 +00:00
|
|
|
|
self = (id)NSAllocateObject(GSArrayClass, 0, [self zone]);
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#else
|
2001-01-08 16:45:36 +00:00
|
|
|
|
self = (id)NSAllocateObject(GSInlineArrayClass, sizeof(id)*count,
|
2010-03-05 09:30:18 +00:00
|
|
|
|
[self zone]);
|
2009-01-13 15:57:38 +00:00
|
|
|
|
#endif
|
2001-01-08 16:45:36 +00:00
|
|
|
|
return [self initWithObjects: objects count: count];
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-07 21:33:38 +00:00
|
|
|
|
- (NSUInteger) count
|
2001-01-08 16:45:36 +00:00
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
2003-10-24 06:53:53 +00:00
|
|
|
|
format: @"Attempt to use uninitialised array"];
|
2001-01-08 16:45:36 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-31 15:31:39 +00:00
|
|
|
|
- (oneway void) release
|
2001-01-08 16:45:36 +00:00
|
|
|
|
{
|
|
|
|
|
return; // placeholders never get released.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) retain
|
|
|
|
|
{
|
|
|
|
|
return self; // placeholders never get retained.
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2001-01-08 23:40:24 +00:00
|
|
|
|
@interface NSGArray : NSArray
|
|
|
|
|
@end
|
|
|
|
|
@implementation NSGArray
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"Warning - decoding archive containing obsolete %@ object - please delete/replace this archive", NSStringFromClass([self class]));
|
2010-02-25 18:49:31 +00:00
|
|
|
|
DESTROY(self);
|
2001-01-08 23:40:24 +00:00
|
|
|
|
self = (id)NSAllocateObject([GSArray class], 0, NSDefaultMallocZone());
|
|
|
|
|
self = [self initWithCoder: aCoder];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@interface NSGMutableArray : NSMutableArray
|
|
|
|
|
@end
|
|
|
|
|
@implementation NSGMutableArray
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"Warning - decoding archive containing obsolete %@ object - please delete/replace this archive", NSStringFromClass([self class]));
|
2010-02-25 18:49:31 +00:00
|
|
|
|
DESTROY(self);
|
2001-01-08 23:40:24 +00:00
|
|
|
|
self = (id)NSAllocateObject([GSMutableArray class], 0, NSDefaultMallocZone());
|
|
|
|
|
self = [self initWithCoder: aCoder];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|