(retain_counts): Make it a NSMapTable instead of a coll_hash.

(NSIncrementExtraRefCount): Update for new retain_counts type.
(NSDecrementExtraRefCountWasZero): Likewise.
([NSObject +initialize]): Likewise.
([NSObject -retainCount]): Likewise.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@989 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mccallum 1996-02-22 23:12:19 +00:00
parent 3e12f5e590
commit 4200045b9f

View file

@ -27,13 +27,10 @@
#include <objc/Protocol.h> #include <objc/Protocol.h>
#include <objc/objc-api.h> #include <objc/objc-api.h>
#include <Foundation/NSMethodSignature.h> #include <Foundation/NSMethodSignature.h>
// #include <Foundation/NSArchiver.h>
// #include <Foundation/NSCoder.h>
#include <Foundation/NSInvocation.h> #include <Foundation/NSInvocation.h>
#include <Foundation/NSAutoreleasePool.h> #include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <objects/collhash.h> #include <Foundation/NSMapTable.h>
#include <objects/eltfuncs.h>
#include <limits.h> #include <limits.h>
extern void (*_objc_error)(id object, const char *format, va_list); extern void (*_objc_error)(id object, const char *format, va_list);
@ -45,7 +42,7 @@ extern int errno;
Doesn't handle exceptions. */ Doesn't handle exceptions. */
/* The hashtable of retain counts on objects */ /* The hashtable of retain counts on objects */
static coll_cache_ptr retain_counts = NULL; static NSMapTable *retain_counts = NULL;
/* The Class responsible for handling autorelease's */ /* The Class responsible for handling autorelease's */
static id autorelease_class = nil; static id autorelease_class = nil;
@ -62,8 +59,13 @@ BOOL NSShouldRetainWithZone(NSObject *anObject, NSZone *requestedZone)
return NO; return NO;
} }
void NSIncrementExtraRefCount(id anObject) void NSIncrementExtraRefCount (id anObject)
{ {
unsigned c = (unsigned) NSMapGet (retain_counts, anObject);
NSMapInsert (retain_counts, anObject, (void*)c+1);
/* xxx Make this more efficient like it was before: */
#if 0
coll_node_ptr n; coll_node_ptr n;
n = coll_hash_node_for_key(retain_counts, anObject); n = coll_hash_node_for_key(retain_counts, anObject);
@ -71,11 +73,25 @@ void NSIncrementExtraRefCount(id anObject)
(n->value.unsigned_int_u)++; (n->value.unsigned_int_u)++;
else else
coll_hash_add(&retain_counts, anObject, (unsigned)1); coll_hash_add(&retain_counts, anObject, (unsigned)1);
#endif
} }
BOOL NSDecrementExtraRefCountWasZero(id anObject) BOOL NSDecrementExtraRefCountWasZero (id anObject)
{ {
BOOL wasZero = YES; unsigned c = (unsigned) NSMapGet (retain_counts, anObject);
if (!c)
return YES;
c--;
if (c)
NSMapInsert (retain_counts, anObject, (void*)c);
else
NSMapRemove (retain_counts, anObject);
return NO;
/* xxx Make this more efficient like it was before: */
#if 0
coll_node_ptr n; coll_node_ptr n;
n = coll_hash_node_for_key(retain_counts, anObject); n = coll_hash_node_for_key(retain_counts, anObject);
@ -84,6 +100,7 @@ BOOL NSDecrementExtraRefCountWasZero(id anObject)
if (!--n->value.unsigned_int_u) if (!--n->value.unsigned_int_u)
coll_hash_remove(retain_counts, anObject); coll_hash_remove(retain_counts, anObject);
return wasZero; return wasZero;
#endif
} }
@implementation NSObject @implementation NSObject
@ -92,11 +109,8 @@ BOOL NSDecrementExtraRefCountWasZero(id anObject)
{ {
if (self == [NSObject class]) if (self == [NSObject class])
{ {
retain_counts = coll_hash_new(64, retain_counts = NSCreateMapTable (NSNonRetainedObjectMapKeyCallBacks,
(coll_hash_func_type) NSIntMapValueCallBacks, 64);
elt_hash_void_ptr,
(coll_compare_func_type)
elt_compare_void_ptrs);
autorelease_class = [NSAutoreleasePool class]; autorelease_class = [NSAutoreleasePool class];
} }
return; return;
@ -397,13 +411,7 @@ BOOL NSDecrementExtraRefCountWasZero(id anObject)
- (unsigned) retainCount - (unsigned) retainCount
{ {
coll_node_ptr n; return (unsigned) NSMapGet (retain_counts, self);
n = coll_hash_node_for_key(retain_counts, self);
if (n)
return n->value.unsigned_int_u;
else
return 0;
} }
+ (unsigned) retainCount + (unsigned) retainCount