mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Zone stuff
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3069 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5e02efeb1d
commit
99129c437a
21 changed files with 1706 additions and 987 deletions
|
@ -30,8 +30,6 @@
|
|||
#include <Foundation/NSPortCoder.h>
|
||||
#include <gnustep/base/Coding.h>
|
||||
|
||||
#define BADREALLOC 1
|
||||
|
||||
@interface NSGArray : NSArray
|
||||
{
|
||||
id *_contents_array;
|
||||
|
@ -60,6 +58,13 @@
|
|||
}
|
||||
}
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)zone
|
||||
{
|
||||
NSGArray *array = NSAllocateObject(self, 0, zone);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (_contents_array) {
|
||||
|
@ -88,7 +93,7 @@
|
|||
for (i = 0; i < count; i++) {
|
||||
if ((_contents_array[i] = [objects[i] retain]) == nil) {
|
||||
_count = i;
|
||||
[self autorelease];
|
||||
[self release];
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Tried to add nil"];
|
||||
}
|
||||
|
@ -98,11 +103,6 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (Class) classForCoder
|
||||
{
|
||||
return [NSArray class];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
unsigned i;
|
||||
|
@ -121,15 +121,17 @@
|
|||
{
|
||||
unsigned count;
|
||||
|
||||
if ([aCoder systemVersion] == 0) {
|
||||
unsigned dummy;
|
||||
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
|
||||
at: &dummy
|
||||
withName: NULL];
|
||||
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
|
||||
at: &dummy
|
||||
withName: NULL];
|
||||
}
|
||||
#if 0
|
||||
unsigned dummy;
|
||||
|
||||
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
|
||||
at: &dummy
|
||||
withName: NULL];
|
||||
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
|
||||
at: &dummy
|
||||
withName: NULL];
|
||||
#endif
|
||||
|
||||
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
|
||||
at: &count
|
||||
withName: NULL];
|
||||
|
@ -208,7 +210,7 @@
|
|||
if (_count < e) {
|
||||
e = _count;
|
||||
}
|
||||
for (i = aRange.location; i < _count; i++) {
|
||||
for (i = aRange.location; i < e; i++) {
|
||||
aBuffer[j++] = _contents_array[i];
|
||||
}
|
||||
}
|
||||
|
@ -266,7 +268,7 @@
|
|||
for (i = 0; i < count; i++) {
|
||||
if ((_contents_array[i] = [objects[i] retain]) == nil) {
|
||||
_count = i;
|
||||
[self autorelease];
|
||||
[self release];
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Tried to add nil"];
|
||||
}
|
||||
|
@ -276,11 +278,6 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (Class) classForCoder
|
||||
{
|
||||
return [NSMutableArray class];
|
||||
}
|
||||
|
||||
- (void) insertObject: (id)anObject atIndex: (unsigned)index
|
||||
{
|
||||
unsigned i;
|
||||
|
@ -297,21 +294,11 @@
|
|||
id *ptr;
|
||||
size_t size = (_capacity + _grow_factor)*sizeof(id);
|
||||
|
||||
#if BADREALLOC
|
||||
ptr = NSZoneMalloc([self zone], size);
|
||||
#else
|
||||
ptr = NSZoneRealloc([self zone], _contents_array, size);
|
||||
#endif
|
||||
if (ptr == 0) {
|
||||
[NSException raise: NSMallocException
|
||||
format: @"Unable to grow"];
|
||||
}
|
||||
#if BADREALLOC
|
||||
if (_contents_array) {
|
||||
memcpy(ptr, _contents_array, _capacity*sizeof(id));
|
||||
NSZoneFree([self zone], _contents_array);
|
||||
}
|
||||
#endif
|
||||
_contents_array = ptr;
|
||||
_capacity += _grow_factor;
|
||||
_grow_factor = _capacity/2;
|
||||
|
@ -339,21 +326,11 @@
|
|||
id *ptr;
|
||||
size_t size = (_capacity + _grow_factor)*sizeof(id);
|
||||
|
||||
#if BADREALLOC
|
||||
ptr = NSZoneMalloc([self zone], size);
|
||||
#else
|
||||
ptr = NSZoneRealloc([self zone], _contents_array, size);
|
||||
#endif
|
||||
if (ptr == 0) {
|
||||
[NSException raise: NSMallocException
|
||||
format: @"Unable to grow"];
|
||||
}
|
||||
#if BADREALLOC
|
||||
if (_contents_array) {
|
||||
memcpy(ptr, _contents_array, _capacity*sizeof(id));
|
||||
NSZoneFree([self zone], _contents_array);
|
||||
}
|
||||
#endif
|
||||
_contents_array = ptr;
|
||||
_capacity += _grow_factor;
|
||||
_grow_factor = _capacity/2;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue