mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
iPerformance and GC improvements
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13726 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5651fe7dbb
commit
ecbcc202a1
15 changed files with 167 additions and 114 deletions
|
@ -3029,7 +3029,7 @@ static NSCharacterSet *tokenSet = nil;
|
|||
}
|
||||
|
||||
/**
|
||||
* Convenience method to set the content of the document aslong with
|
||||
* Convenience method to set the content of the document along with
|
||||
* creating a content-type header for it.
|
||||
*/
|
||||
- (BOOL) setContent: (id)newContent
|
||||
|
|
|
@ -464,6 +464,7 @@ static SEL eqSel;
|
|||
}
|
||||
_count--;
|
||||
RELEASE(_contents_array[_count]);
|
||||
_contents_array[_count] = 0;
|
||||
}
|
||||
|
||||
- (void) removeObject: (id)anObject
|
||||
|
@ -504,6 +505,7 @@ static SEL eqSel;
|
|||
_contents_array[pos-1] = _contents_array[pos];
|
||||
}
|
||||
_count--;
|
||||
_contents_array[_count] = 0;
|
||||
RELEASE(obj);
|
||||
}
|
||||
}
|
||||
|
@ -533,6 +535,7 @@ static SEL eqSel;
|
|||
_contents_array[index] = _contents_array[index+1];
|
||||
index++;
|
||||
}
|
||||
_contents_array[_count] = 0;
|
||||
RELEASE(obj); /* Adjust array BEFORE releasing object. */
|
||||
}
|
||||
|
||||
|
@ -560,6 +563,7 @@ static SEL eqSel;
|
|||
_contents_array[pos-1] = _contents_array[pos];
|
||||
}
|
||||
_count--;
|
||||
_contents_array[_count] = 0;
|
||||
RELEASE(obj);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,7 +129,12 @@ static Class mutableSetClass;
|
|||
{
|
||||
if (map.nodeCount > 0)
|
||||
{
|
||||
return map.firstNode->key.obj;
|
||||
GSIMapBucket bucket = map.buckets;
|
||||
while(1)
|
||||
if(bucket->firstNode)
|
||||
return bucket->firstNode->key.obj;
|
||||
else
|
||||
bucket++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1285,9 +1285,12 @@ static Class tcpPortClass;
|
|||
h->myLock = [NSRecursiveLock new];
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&hEnum);
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&mEnum);
|
||||
}
|
||||
NSEndMapTableEnumeration(&pEnum);
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
removeObserver: self
|
||||
|
@ -1656,6 +1659,7 @@ static Class tcpPortClass;
|
|||
fds[(*count)++] = sock;
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&me);
|
||||
DO_UNLOCK(myLock);
|
||||
}
|
||||
|
||||
|
@ -1675,9 +1679,11 @@ static Class tcpPortClass;
|
|||
if ([handle recvPort] == recvPort)
|
||||
{
|
||||
DO_UNLOCK(myLock);
|
||||
NSEndMapTableEnumeration(&me);
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&me);
|
||||
if (handle == nil)
|
||||
{
|
||||
int opt = 1;
|
||||
|
|
|
@ -517,13 +517,15 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
while (NSNextMapEnumeratorPair(&enumerate, &key, (void **)&bundle))
|
||||
{
|
||||
if (bundle->_bundleType == NSBUNDLE_FRAMEWORK)
|
||||
continue;
|
||||
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ([array indexOfObjectIdenticalTo: bundle] == NSNotFound)
|
||||
{
|
||||
[array addObject: bundle];
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&enumerate);
|
||||
}
|
||||
[load_lock unlock];
|
||||
return array;
|
||||
|
@ -546,6 +548,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
[array addObject: bundle];
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&enumerate);
|
||||
[load_lock unlock];
|
||||
return array;
|
||||
}
|
||||
|
|
|
@ -292,6 +292,7 @@ existingConnection(NSPort *receivePort, NSPort *sendPort)
|
|||
break;
|
||||
}
|
||||
}
|
||||
NSEndHashTableEnumeration(&enumerator);
|
||||
F_UNLOCK(connection_table_gate);
|
||||
return c;
|
||||
}
|
||||
|
@ -381,6 +382,7 @@ static BOOL multi_threaded = NO;
|
|||
c->_refGate = [NSRecursiveLock new];
|
||||
}
|
||||
}
|
||||
NSEndHashTableEnumeration(&enumerator);
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
removeObserver: self
|
||||
|
@ -2067,6 +2069,7 @@ static void retEncoder (DOContext *ctxt)
|
|||
count++;
|
||||
}
|
||||
}
|
||||
NSEndHashTableEnumeration(&enumerator);
|
||||
M_UNLOCK(connection_table_gate);
|
||||
|
||||
return count;
|
||||
|
|
|
@ -977,7 +977,7 @@ failure:
|
|||
#if GS_WITH_GC == 0
|
||||
*(char**)data = (char*)NSZoneMalloc(NSDefaultMallocZone(), len);
|
||||
#else
|
||||
*(char**)data = (char*)NSZoneMalloc(NSAtomicMallocZone(), len);
|
||||
*(char**)data = (char*)NSZoneMalloc(GSAtomicMallocZone(), len);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1044,7 +1044,7 @@ failure:
|
|||
#if GS_WITH_GC == 0
|
||||
*(char**)data = (char*)NSZoneMalloc(NSDefaultMallocZone(), len);
|
||||
#else
|
||||
*(char**)data = (char*)NSZoneMalloc(NSAtomicMallocZone(), len);
|
||||
*(char**)data = (char*)NSZoneMalloc(GSAtomicMallocZone(), len);
|
||||
#endif
|
||||
[self deserializeDataAt: *(char**)data
|
||||
ofObjCType: type
|
||||
|
@ -2096,7 +2096,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
|||
#if GS_WITH_GC == 0
|
||||
*(char**)data = (char*)NSZoneMalloc(NSDefaultMallocZone(), len+1);
|
||||
#else
|
||||
*(char**)data = (char*)NSZoneMalloc(NSAtomicMallocZone(), len+1);
|
||||
*(char**)data = (char*)NSZoneMalloc(GSAtomicMallocZone(), len+1);
|
||||
#endif
|
||||
}
|
||||
getBytes(*(void**)data, bytes, len, length, cursor);
|
||||
|
@ -2160,7 +2160,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
|||
#if GS_WITH_GC == 0
|
||||
*(char**)data = (char*)NSZoneMalloc(NSDefaultMallocZone(), len);
|
||||
#else
|
||||
*(char**)data = (char*)NSZoneMalloc(NSAtomicMallocZone(), len);
|
||||
*(char**)data = (char*)NSZoneMalloc(GSAtomicMallocZone(), len);
|
||||
#endif
|
||||
[self deserializeDataAt: *(char**)data
|
||||
ofObjCType: type
|
||||
|
|
|
@ -122,15 +122,14 @@ NSCompareHashTables(NSHashTable *table1, NSHashTable *table2)
|
|||
}
|
||||
else
|
||||
{
|
||||
GSIMapNode n = t1->firstNode;
|
||||
|
||||
while (n != 0)
|
||||
{
|
||||
NSHashEnumerator enumerator = GSIMapEnumeratorForMap((GSIMapTable)t1);
|
||||
GSIMapNode n;
|
||||
while ((n = GSIMapEnumeratorNextNode(&enumerator)) != 0)
|
||||
{
|
||||
if (GSIMapNodeForKey(t2, n->key) == 0)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
n = n->nextInMap;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
@ -144,7 +143,8 @@ NSCopyHashTableWithZone(NSHashTable *table, NSZone *zone)
|
|||
{
|
||||
GSIMapTable t;
|
||||
GSIMapNode n;
|
||||
|
||||
NSHashEnumerator enumerator;
|
||||
|
||||
if (table == 0)
|
||||
{
|
||||
NSWarnFLog(@"Nul table argument supplied");
|
||||
|
@ -154,11 +154,10 @@ NSCopyHashTableWithZone(NSHashTable *table, NSZone *zone)
|
|||
t = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t));
|
||||
GSIMapInitWithZoneAndCapacity(t, zone, ((GSIMapTable)table)->nodeCount);
|
||||
t->extra = ((GSIMapTable)table)->extra;
|
||||
n = ((GSIMapTable)table)->firstNode;
|
||||
while (n != 0)
|
||||
enumerator = GSIMapEnumeratorForMap((GSIMapTable)table);
|
||||
while ((n = GSIMapEnumeratorNextNode(&enumerator)) != 0)
|
||||
{
|
||||
GSIMapAddKey(t, n->key);
|
||||
n = n->nextInMap;
|
||||
}
|
||||
|
||||
return (NSHashTable*)t;
|
||||
|
@ -225,7 +224,7 @@ NSCreateHashTableWithZone(
|
|||
|
||||
/**
|
||||
* Function to be called when finished with the enumerator.
|
||||
* Not required in GNUstep ... just provided for MacOS-X compatibility.
|
||||
* This permits memory used by the enumerator to be released.
|
||||
*/
|
||||
void
|
||||
NSEndHashTableEnumeration(NSHashEnumerator *enumerator)
|
||||
|
@ -233,7 +232,11 @@ NSEndHashTableEnumeration(NSHashEnumerator *enumerator)
|
|||
if (enumerator == 0)
|
||||
{
|
||||
NSWarnFLog(@"Nul enumerator argument supplied");
|
||||
return;
|
||||
}
|
||||
#if GS_WITH_GC
|
||||
memset(enumerator, 0, sizeof(*enumerator));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,7 +248,7 @@ NSEnumerateHashTable(NSHashTable *table)
|
|||
{
|
||||
if (table == 0)
|
||||
{
|
||||
NSHashEnumerator v = { 0, 0 };
|
||||
NSHashEnumerator v = { 0, 0, 0 };
|
||||
|
||||
NSWarnFLog(@"Nul table argument supplied");
|
||||
return v;
|
||||
|
|
|
@ -99,6 +99,7 @@ NSAllMapTableKeys(NSMapTable *table)
|
|||
{
|
||||
[keyArray addObject: key];
|
||||
}
|
||||
NSEndMapTableEnumeration(&enumerator);
|
||||
return keyArray;
|
||||
}
|
||||
|
||||
|
@ -131,6 +132,7 @@ NSAllMapTableValues(NSMapTable *table)
|
|||
{
|
||||
[valueArray addObject: value];
|
||||
}
|
||||
NSEndMapTableEnumeration(&enumerator);
|
||||
return valueArray;
|
||||
}
|
||||
|
||||
|
@ -169,16 +171,15 @@ NSCompareMapTables(NSMapTable *table1, NSMapTable *table2)
|
|||
}
|
||||
else
|
||||
{
|
||||
GSIMapNode n = t1->firstNode;
|
||||
|
||||
while (n != 0)
|
||||
{
|
||||
if (GSIMapNodeForKey(t2, n->key) == 0)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
n = n->nextInMap;
|
||||
}
|
||||
NSMapEnumerator enumerator = GSIMapEnumeratorForMap((GSIMapTable)t1);
|
||||
GSIMapNode n;
|
||||
while ((n = GSIMapEnumeratorNextNode(&enumerator)) != 0)
|
||||
{
|
||||
if (GSIMapNodeForKey(t2, n->key) == 0)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +192,8 @@ NSCopyMapTableWithZone(NSMapTable *table, NSZone *zone)
|
|||
{
|
||||
GSIMapTable t;
|
||||
GSIMapNode n;
|
||||
|
||||
NSMapEnumerator enumerator;
|
||||
|
||||
if (table == 0)
|
||||
{
|
||||
NSWarnFLog(@"Nul table argument supplied");
|
||||
|
@ -202,11 +204,10 @@ NSCopyMapTableWithZone(NSMapTable *table, NSZone *zone)
|
|||
GSIMapInitWithZoneAndCapacity(t, zone, ((GSIMapTable)table)->nodeCount);
|
||||
t->extra.k = ((GSIMapTable)table)->extra.k;
|
||||
t->extra.v = ((GSIMapTable)table)->extra.v;
|
||||
n = ((GSIMapTable)table)->firstNode;
|
||||
while (n != 0)
|
||||
enumerator = GSIMapEnumeratorForMap((GSIMapTable)table);
|
||||
while ((n = GSIMapEnumeratorNextNode(&enumerator)) != 0)
|
||||
{
|
||||
GSIMapAddPair(t, n->key, n->value);
|
||||
n = n->nextInMap;
|
||||
}
|
||||
|
||||
return (NSMapTable*)t;
|
||||
|
@ -284,7 +285,7 @@ NSCreateMapTableWithZone(
|
|||
|
||||
/**
|
||||
* Function to be called when finished with the enumerator.
|
||||
* Not required in GNUstep ... just provided for MacOS-X compatibility.
|
||||
* This permits memory used by the enumerator to be released!
|
||||
*/
|
||||
void
|
||||
NSEndMapTableEnumeration(NSMapEnumerator *enumerator)
|
||||
|
@ -292,7 +293,11 @@ NSEndMapTableEnumeration(NSMapEnumerator *enumerator)
|
|||
if (enumerator == 0)
|
||||
{
|
||||
NSWarnFLog(@"Nul enumerator argument supplied");
|
||||
return;
|
||||
}
|
||||
#if GS_WITH_GC
|
||||
memset(enumerator, 0, sizeof(*enumerator));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -608,6 +613,7 @@ NSStringFromMapTable(NSMapTable *table)
|
|||
(t->extra.k.describe)(table, key),
|
||||
(t->extra.v.describe)(table, value)];
|
||||
}
|
||||
NSEndMapTableEnumeration(&enumerator);
|
||||
return string;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,9 +52,11 @@
|
|||
extern BOOL __objc_responds_to(id, SEL);
|
||||
#endif
|
||||
|
||||
#if GS_WITH_GC == 0
|
||||
@class _FastMallocBuffer;
|
||||
static Class fastMallocClass;
|
||||
static unsigned fastMallocOffset;
|
||||
#endif
|
||||
|
||||
static Class NSConstantStringClass;
|
||||
|
||||
|
@ -726,15 +728,13 @@ static BOOL double_release_check_enabled = NO;
|
|||
autorelease_class = [NSAutoreleasePool class];
|
||||
autorelease_sel = @selector(addObject:);
|
||||
autorelease_imp = [autorelease_class methodForSelector: autorelease_sel];
|
||||
fastMallocClass = [_FastMallocBuffer class];
|
||||
#if GS_WITH_GC == 0
|
||||
fastMallocClass = [_FastMallocBuffer class];
|
||||
#if !defined(REFCNT_LOCAL)
|
||||
GSIMapInitWithZoneAndCapacity(&retain_counts,
|
||||
NSDefaultMallocZone(), 1024);
|
||||
#endif
|
||||
fastMallocOffset = fastMallocClass->instance_size % ALIGN;
|
||||
#else
|
||||
fastMallocOffset = 0;
|
||||
#endif
|
||||
NSConstantStringClass = [NSString constantStringClass];
|
||||
GSBuildStrings();
|
||||
|
@ -1584,11 +1584,13 @@ static BOOL double_release_check_enabled = NO;
|
|||
/*
|
||||
* Stuff for temporary memory management.
|
||||
*/
|
||||
#if GS_WITH_GC == 0
|
||||
@interface _FastMallocBuffer : NSObject
|
||||
@end
|
||||
|
||||
@implementation _FastMallocBuffer
|
||||
@end
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Function for giving us the fastest possible allocation of memory to
|
||||
|
@ -1597,12 +1599,16 @@ static BOOL double_release_check_enabled = NO;
|
|||
void *
|
||||
_fastMallocBuffer(unsigned size)
|
||||
{
|
||||
#if GS_WITH_GC
|
||||
return GC_malloc(size);
|
||||
#else
|
||||
_FastMallocBuffer *o;
|
||||
|
||||
o = (_FastMallocBuffer*)NSAllocateObject(fastMallocClass,
|
||||
size + fastMallocOffset, NSDefaultMallocZone());
|
||||
(*autorelease_imp)(autorelease_class, autorelease_sel, o);
|
||||
return ((void*)&o[1])+fastMallocOffset;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1382,6 +1382,7 @@ if (0) {
|
|||
}
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&enumerator);
|
||||
|
||||
/*
|
||||
* Finally, fire the requests.
|
||||
|
@ -2115,6 +2116,7 @@ if (0) {
|
|||
}
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&enumerator);
|
||||
}
|
||||
|
||||
- (void) configureAsServer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue