Tidied a little, removing redundant code.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20154 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2004-09-27 06:58:23 +00:00
parent 2a49f09265
commit d5460c236d
2 changed files with 41 additions and 79 deletions

View file

@ -1,3 +1,8 @@
2004-09-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSDebug.m: Remove checks for existence of lock ... it always
exists, so the checks are useless.
2004-09-24 Richard Frith-Macdonald <rfm@gnu.org> 2004-09-24 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSArray.m: Make perform methods enumerate forwards. * Source/GSArray.m: Make perform methods enumerate forwards.

View file

@ -58,7 +58,7 @@ static table_entry* the_table = 0;
static BOOL debug_allocation = NO; static BOOL debug_allocation = NO;
static NSLock *uniqueLock; static NSLock *uniqueLock = nil;
static const char* _GSDebugAllocationList(BOOL difference); static const char* _GSDebugAllocationList(BOOL difference);
static const char* _GSDebugAllocationListAll(void); static const char* _GSDebugAllocationListAll(void);
@ -88,10 +88,7 @@ void
GSSetDebugAllocationFunctions(void (*newAddObjectFunc)(Class c, id o), GSSetDebugAllocationFunctions(void (*newAddObjectFunc)(Class c, id o),
void (*newRemoveObjectFunc)(Class c, id o)) void (*newRemoveObjectFunc)(Class c, id o))
{ {
if (uniqueLock != nil)
{
[uniqueLock lock]; [uniqueLock lock];
}
if (newAddObjectFunc && newRemoveObjectFunc) if (newAddObjectFunc && newRemoveObjectFunc)
{ {
@ -105,10 +102,7 @@ GSSetDebugAllocationFunctions(void (*newAddObjectFunc)(Class c, id o),
_GSDebugAllocationRemoveFunc = _GSDebugAllocationRemove; _GSDebugAllocationRemoveFunc = _GSDebugAllocationRemove;
} }
if (uniqueLock != nil)
{
[uniqueLock unlock]; [uniqueLock unlock];
}
} }
/** /**
@ -129,7 +123,7 @@ GSDebugAllocationActive(BOOL active)
BOOL old = debug_allocation; BOOL old = debug_allocation;
[GSDebugAlloc class]; /* Ensure thread support is working */ [GSDebugAlloc class]; /* Ensure thread support is working */
debug_allocation = active; debug_allocation = active ? YES : NO;
return old; return old;
} }
@ -160,15 +154,12 @@ GSDebugAllocationActiveRecordingObjects(Class c)
{ {
if (the_table[i].class == c) if (the_table[i].class == c)
{ {
if (uniqueLock != nil)
[uniqueLock lock]; [uniqueLock lock];
the_table[i].is_recording = YES; the_table[i].is_recording = YES;
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return; return;
} }
} }
if (uniqueLock != nil)
[uniqueLock lock]; [uniqueLock lock];
if (num_classes >= table_size) if (num_classes >= table_size)
{ {
@ -179,7 +170,6 @@ GSDebugAllocationActiveRecordingObjects(Class c)
if (tmp == 0) if (tmp == 0)
{ {
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return; return;
} }
@ -202,7 +192,6 @@ GSDebugAllocationActiveRecordingObjects(Class c)
the_table[num_classes].num_recorded_objects = 0; the_table[num_classes].num_recorded_objects = 0;
the_table[num_classes].stack_size = 0; the_table[num_classes].stack_size = 0;
num_classes++; num_classes++;
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
} }
@ -215,7 +204,7 @@ GSDebugAllocationAdd(Class c, id o)
void void
_GSDebugAllocationAdd(Class c, id o) _GSDebugAllocationAdd(Class c, id o)
{ {
if (debug_allocation) if (debug_allocation == YES)
{ {
unsigned int i; unsigned int i;
@ -223,7 +212,6 @@ _GSDebugAllocationAdd(Class c, id o)
{ {
if (the_table[i].class == c) if (the_table[i].class == c)
{ {
if (uniqueLock != nil)
[uniqueLock lock]; [uniqueLock lock];
the_table[i].count++; the_table[i].count++;
the_table[i].total++; the_table[i].total++;
@ -244,7 +232,6 @@ _GSDebugAllocationAdd(Class c, id o)
more * sizeof(id)); more * sizeof(id));
if (tmp == 0) if (tmp == 0)
{ {
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return; return;
} }
@ -254,7 +241,6 @@ _GSDebugAllocationAdd(Class c, id o)
if (tmp1 == 0) if (tmp1 == 0)
{ {
NSZoneFree(NSDefaultMallocZone(), tmp); NSZoneFree(NSDefaultMallocZone(), tmp);
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return; return;
} }
@ -284,12 +270,10 @@ _GSDebugAllocationAdd(Class c, id o)
[the_table[i].num_recorded_objects] = nil; [the_table[i].num_recorded_objects] = nil;
the_table[i].num_recorded_objects++; the_table[i].num_recorded_objects++;
} }
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return; return;
} }
} }
if (uniqueLock != nil)
[uniqueLock lock]; [uniqueLock lock];
if (num_classes >= table_size) if (num_classes >= table_size)
{ {
@ -300,7 +284,6 @@ _GSDebugAllocationAdd(Class c, id o)
if (tmp == 0) if (tmp == 0)
{ {
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return; /* Argh */ return; /* Argh */
} }
@ -323,7 +306,6 @@ _GSDebugAllocationAdd(Class c, id o)
the_table[num_classes].num_recorded_objects = 0; the_table[num_classes].num_recorded_objects = 0;
the_table[num_classes].stack_size = 0; the_table[num_classes].stack_size = 0;
num_classes++; num_classes++;
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
} }
} }
@ -441,7 +423,6 @@ GSDebugAllocationClassList()
size_t siz; size_t siz;
unsigned int i; unsigned int i;
if (uniqueLock != nil)
[uniqueLock lock]; [uniqueLock lock];
siz = sizeof(Class) * (num_classes + 1); siz = sizeof(Class) * (num_classes + 1);
@ -453,7 +434,6 @@ GSDebugAllocationClassList()
} }
ans[num_classes] = NULL; ans[num_classes] = NULL;
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return ans; return ans;
@ -479,16 +459,10 @@ GSDebugAllocationList(BOOL changeFlag)
{ {
return "Debug allocation system is not active!\n"; return "Debug allocation system is not active!\n";
} }
if (uniqueLock != nil)
{
[uniqueLock lock]; [uniqueLock lock];
}
ans = _GSDebugAllocationList(changeFlag); ans = _GSDebugAllocationList(changeFlag);
d = [NSData dataWithBytes: ans length: strlen(ans) + 1]; d = [NSData dataWithBytes: ans length: strlen(ans) + 1];
if (uniqueLock != nil)
{
[uniqueLock unlock]; [uniqueLock unlock];
}
return (const char*)[d bytes]; return (const char*)[d bytes];
} }
@ -583,16 +557,10 @@ GSDebugAllocationListAll()
{ {
return "Debug allocation system is not active!\n"; return "Debug allocation system is not active!\n";
} }
if (uniqueLock != nil)
{
[uniqueLock lock]; [uniqueLock lock];
}
ans = _GSDebugAllocationListAll(); ans = _GSDebugAllocationListAll();
d = [NSData dataWithBytes: ans length: strlen(ans)+1]; d = [NSData dataWithBytes: ans length: strlen(ans)+1];
if (uniqueLock != nil)
{
[uniqueLock unlock]; [uniqueLock unlock];
}
return (const char*)[d bytes]; return (const char*)[d bytes];
} }
@ -659,7 +627,7 @@ GSDebugAllocationRemove(Class c, id o)
void void
_GSDebugAllocationRemove(Class c, id o) _GSDebugAllocationRemove(Class c, id o)
{ {
if (debug_allocation) if (debug_allocation == YES)
{ {
unsigned int i; unsigned int i;
@ -669,7 +637,6 @@ _GSDebugAllocationRemove(Class c, id o)
{ {
id tag = nil; id tag = nil;
if (uniqueLock != nil)
[uniqueLock lock]; [uniqueLock lock];
the_table[i].count--; the_table[i].count--;
if (the_table[i].is_recording) if (the_table[i].is_recording)
@ -705,7 +672,6 @@ _GSDebugAllocationRemove(Class c, id o)
; ;
} }
} }
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
RELEASE(tag); RELEASE(tag);
return; return;
@ -733,7 +699,6 @@ GSDebugAllocationTagRecordedObject(id object, id tag)
{ {
return nil; return nil;
} }
if (uniqueLock != nil)
[uniqueLock lock]; [uniqueLock lock];
for (i = 0; i < num_classes; i++) for (i = 0; i < num_classes; i++)
@ -748,7 +713,6 @@ GSDebugAllocationTagRecordedObject(id object, id tag)
|| the_table[i].is_recording == NO || the_table[i].is_recording == NO
|| the_table[i].num_recorded_objects == 0) || the_table[i].num_recorded_objects == 0)
{ {
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return nil; return nil;
} }
@ -763,7 +727,6 @@ GSDebugAllocationTagRecordedObject(id object, id tag)
} }
} }
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return AUTORELEASE(o); return AUTORELEASE(o);
} }
@ -790,7 +753,6 @@ GSDebugAllocationListRecordedObjects(Class c)
return nil; return nil;
} }
if (uniqueLock != nil)
[uniqueLock lock]; [uniqueLock lock];
for (i = 0; i < num_classes; i++) for (i = 0; i < num_classes; i++)
@ -803,21 +765,18 @@ GSDebugAllocationListRecordedObjects(Class c)
if (i == num_classes) if (i == num_classes)
{ {
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return nil; return nil;
} }
if (the_table[i].is_recording == NO) if (the_table[i].is_recording == NO)
{ {
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return nil; return nil;
} }
if (the_table[i].num_recorded_objects == 0) if (the_table[i].num_recorded_objects == 0)
{ {
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return [NSArray array]; return [NSArray array];
} }
@ -826,7 +785,6 @@ GSDebugAllocationListRecordedObjects(Class c)
the_table[i].num_recorded_objects * sizeof(id)); the_table[i].num_recorded_objects * sizeof(id));
if (tmp == 0) if (tmp == 0)
{ {
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
return nil; return nil;
} }
@ -843,7 +801,6 @@ GSDebugAllocationListRecordedObjects(Class c)
} }
/* Then, we bravely unlock the lock */ /* Then, we bravely unlock the lock */
if (uniqueLock != nil)
[uniqueLock unlock]; [uniqueLock unlock];
/* Only then we create an array with them - this is now safe as we /* Only then we create an array with them - this is now safe as we