Minor tidyp ... change a couple of macro names

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17904 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-10-16 20:41:50 +00:00
parent d113f2549c
commit 7f5174c76a
3 changed files with 40 additions and 21 deletions

View file

@ -1,3 +1,9 @@
Thu Oct 16 21:45:00 2003 Richard Frith-Macdonald <rfm@gnu.org>
* GSPrivate.h: Try to think of better macro names and documentation
for stack/heap allocation.
* NSArray.m: Use new macro names.
Thu Oct 16 19:30:00 2003 Richard Frith-Macdonald <rfm@gnu.org>
* configure.ac: Check for sigaction()

View file

@ -23,17 +23,30 @@
#ifndef __GSPrivate_h_
#define __GSPrivate_h_
#include "GNUstepBase/GSObjCRuntime.h"
/*
* Macros to manage memory for chunks of code that need to work with
* arrays of objects. Use OBUFBEGIN() to start the block of code using
* the array and OBUFEND() to end it. The idea is to ensure that small
/**
* Macro to manage memory for chunks of code that need to work with
* arrays of objects. Use this to start the block of code using
* the array and GS_ENDIDBUF() to end it. The idea is to ensure that small
* arrays are allocated on the stack (for speed), but large arrays are
* allocated from the heap (to avoid stack overflow).
*/
#define OBUFMAX 1024
#define OBUFBEGIN(P, S) { id _obuf[(S) <= OBUFMAX ? (S) : 0]; id *_base = ((S) <= OBUFMAX) ? _obuf : (id*)NSZoneMalloc(NSDefaultMallocZone(), (S) * sizeof(id)); id *(P) = _base;
#define OBUFEND() if (_base != _obuf) NSZoneFree(NSDefaultMallocZone(), _base); }
#define GS_BEGINIDBUF(P, S) { \
id _obuf[(S) <= GS_MAX_OBJECTS_FROM_STACK ? (S) : 0]; \
id *_base = ((S) <= GS_MAX_OBJECTS_FROM_STACK) ? _obuf \
: (id*)NSZoneMalloc(NSDefaultMallocZone(), (S) * sizeof(id)); \
id *(P) = _base;
/**
* Macro to manage memory for chunks of code that need to work with
* arrays of objects. Use GS_BEGINIDBUF() to start the block of code using
* the array and this macro to end it.
*/
#define GS_ENDIDBUF() \
if (_base != _obuf) \
NSZoneFree(NSDefaultMallocZone(), _base); \
}
/*
* Function to get the name of a string encoding as an NSString.

View file

@ -271,14 +271,14 @@ static SEL rlSel;
}
else
{
OBUFBEGIN(objects, c+1)
GS_BEGINIDBUF(objects, c+1)
[self getObjects: objects];
objects[c] = anObject;
na = [[GSArrayClass allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects count: c+1];
OBUFEND()
GS_ENDIDBUF()
}
return AUTORELEASE(na);
}
@ -295,13 +295,13 @@ static SEL rlSel;
c = [self count];
l = [anotherArray count];
OBUFBEGIN(objects, c+l)
GS_BEGINIDBUF(objects, c+l)
[self getObjects: objects];
[anotherArray getObjects: &objects[c]];
na = [NSArrayClass arrayWithObjects: objects count: c+l];
OBUFEND()
GS_ENDIDBUF()
return na;
}
@ -358,13 +358,13 @@ static SEL rlSel;
if (count > 0)
{
OBUFBEGIN(a, count)
GS_BEGINIDBUF(a, count)
[self getObjects: a];
[aCoder encodeArrayOfObjCType: @encode(id)
count: count
at: a];
OBUFEND()
GS_ENDIDBUF()
}
}
@ -501,7 +501,7 @@ static SEL rlSel;
- (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy
{
unsigned c = [array count];
OBUFBEGIN(objects, c)
GS_BEGINIDBUF(objects, c)
[array getObjects: objects];
if (shouldCopy == YES)
@ -524,7 +524,7 @@ static SEL rlSel;
{
self = [self initWithObjects: objects count: c];
}
OBUFEND()
GS_ENDIDBUF()
return self;
}
@ -536,11 +536,11 @@ static SEL rlSel;
- (id) initWithArray: (NSArray*)array
{
unsigned c = [array count];
OBUFBEGIN(objects, c)
GS_BEGINIDBUF(objects, c)
[array getObjects: objects];
self = [self initWithObjects: objects count: c];
OBUFEND()
GS_ENDIDBUF()
return self;
}
@ -556,7 +556,7 @@ static SEL rlSel;
at: &count];
if (count > 0)
{
OBUFBEGIN(contents, count)
GS_BEGINIDBUF(contents, count)
[aCoder decodeArrayOfObjCType: @encode(id)
count: count
@ -568,7 +568,7 @@ static SEL rlSel;
[contents[count] release];
}
#endif
OBUFEND()
GS_ENDIDBUF()
}
else
{
@ -984,11 +984,11 @@ compare(id elem1, id elem2, void* context)
}
else
{
OBUFBEGIN(objects, aRange.length)
GS_BEGINIDBUF(objects, aRange.length)
[self getObjects: objects range: aRange];
na = [NSArray arrayWithObjects: objects count: aRange.length];
OBUFEND()
GS_ENDIDBUF()
}
return na;
}