mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Removed retain_count stuff. Now calling objc_set_autorelease_class().
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a9953e53b2
commit
883031612e
1 changed files with 5 additions and 97 deletions
|
@ -21,86 +21,32 @@
|
|||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <objects/stdobject.h>
|
||||
#include <objects/AutoreleasePool.h>
|
||||
#include <objects/collhash.h>
|
||||
#include <objects/eltfuncs.h>
|
||||
#include <objects/objc-malloc.h>
|
||||
#include <limits.h>
|
||||
#include <objects/ObjectRetaining.h>
|
||||
|
||||
/* Doesn't handle multi-threaded stuff.
|
||||
Doesn't handle exceptions. */
|
||||
|
||||
/* We should add this to the runtime:
|
||||
We should use cache_ptr's instead, (adding the necessary code)
|
||||
Put the stuff from initialize into a runtime init function.
|
||||
/* Put the stuff from initialize into a runtime init function.
|
||||
This class should be made more efficient, especially:
|
||||
[[Autorelease alloc] init]
|
||||
[current_pool addObject:o] (REALLOC-case)
|
||||
*/
|
||||
|
||||
static AutoreleasePool *current_pool = nil;
|
||||
static coll_cache_ptr retain_counts = NULL;
|
||||
|
||||
#define DEFAULT_SIZE 64
|
||||
|
||||
|
||||
void
|
||||
objc_retain_object (id anObj)
|
||||
{
|
||||
coll_node_ptr n;
|
||||
|
||||
assert(retain_counts);
|
||||
n = coll_hash_node_for_key(retain_counts, anObj);
|
||||
if (n)
|
||||
(n->value.unsigned_int_u)++;
|
||||
else
|
||||
coll_hash_add(&retain_counts, anObj, (unsigned)1);
|
||||
}
|
||||
|
||||
void
|
||||
objc_release_object (id anObj)
|
||||
{
|
||||
coll_node_ptr n;
|
||||
|
||||
assert(retain_counts);
|
||||
n = coll_hash_node_for_key(retain_counts, anObj);
|
||||
if (n)
|
||||
{
|
||||
(n->value.unsigned_int_u)--;
|
||||
if (n->value.unsigned_int_u)
|
||||
return;
|
||||
coll_hash_remove(retain_counts, anObj);
|
||||
}
|
||||
[anObj dealloc];
|
||||
}
|
||||
|
||||
/* Careful, this doesn't include autoreleases */
|
||||
unsigned
|
||||
objc_retain_count (id anObj)
|
||||
{
|
||||
coll_node_ptr n;
|
||||
|
||||
assert(retain_counts);
|
||||
n = coll_hash_node_for_key(retain_counts, anObj);
|
||||
if (n)
|
||||
return n->value.unsigned_int_u;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@implementation AutoreleasePool
|
||||
|
||||
+ initialize
|
||||
{
|
||||
if (self == [AutoreleasePool class])
|
||||
{
|
||||
retain_counts = coll_hash_new(64,
|
||||
(coll_hash_func_type)
|
||||
elt_hash_void_ptr,
|
||||
(coll_compare_func_type)
|
||||
elt_compare_void_ptrs);
|
||||
current_pool = [[AutoreleasePool alloc] init];
|
||||
}
|
||||
objc_set_autorelease_class(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -161,46 +107,8 @@ objc_retain_count (id anObj)
|
|||
|
||||
- autorelease
|
||||
{
|
||||
[self error:"Don't call this"];
|
||||
[self error:"Don't call `-autorelease' on a AutoreleasePool"];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (unsigned) retainCount
|
||||
{
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation Object (Retaining)
|
||||
|
||||
- retain
|
||||
{
|
||||
objc_retain_object(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (oneway void) release
|
||||
{
|
||||
objc_release_object(self);
|
||||
}
|
||||
|
||||
- autorelease
|
||||
{
|
||||
[current_pool addObject:self];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
object_dispose(self);
|
||||
}
|
||||
|
||||
- (unsigned) retainCount
|
||||
{
|
||||
return objc_retain_count(self);
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue