Tidied caching stuff

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3035 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1998-10-07 11:26:18 +00:00
parent 93c529ee3d
commit 1123e8337e
2 changed files with 42 additions and 22 deletions

View file

@ -79,7 +79,7 @@ typedef struct {
Class _NSGMutableCString;
Class _NXConstantString;
} fastCls;
extern fastCls _fastCls; /* Populated by NSObject */
extern fastCls _fastCls; /* Populated by _fastBuildCache() */
/*
* Structure to cache method implementation information.
@ -96,7 +96,16 @@ typedef struct {
BOOL (*_NSGString_isEqual_)();
BOOL (*_NSGCString_isEqual_)();
} fastImp;
extern fastImp _fastImp; /* Populated by NSObject */
extern fastImp _fastImp; /* Populated by _fastBuildCache() */
/*
* The '_fastBuildCache()' function is called to populate the cache
* structures. This is (at present) called in [NSObject +initialize]
* but you may call it explicitly later to repopulate the cache after
* changes have been made to the runtime by loading of categories or
* by classes posing as other classes.
*/
extern void _fastBuildCache();
/*
* Fast access to class info - DON'T pass nil to these!

View file

@ -42,6 +42,31 @@
fastCls _fastCls; /* Structure to cache classes. */
fastImp _fastImp; /* Structure to cache methods. */
void _fastBuildCache()
{
/*
* Cache some classes for quick access later.
*/
_fastCls._NSString = [NSString class];
_fastCls._NSGString = [NSGString class];
_fastCls._NSGMutableString = [NSGMutableString class];
_fastCls._NSGCString = [NSGCString class];
_fastCls._NSGMutableCString = [NSGMutableCString class];
_fastCls._NXConstantString = [NXConstantString class];
/*
* Cache some method implementations for quick access later.
*/
_fastImp._NSString_hash = (unsigned (*)())[_fastCls._NSString
instanceMethodForSelector: @selector(hash)];
_fastImp._NSGString_hash = (unsigned (*)())[_fastCls._NSGString
instanceMethodForSelector: @selector(hash)];
_fastImp._NSGString_isEqual_ = (BOOL (*)())[_fastCls._NSGString
instanceMethodForSelector: @selector(isEqual:)];
_fastImp._NSGCString_isEqual_ = (BOOL (*)())[_fastCls._NSGCString
instanceMethodForSelector: @selector(isEqual:)];
}
/*
* Reference count and memory management
@ -314,26 +339,7 @@ static BOOL double_release_check_enabled = NO;
retain_counts_gate = objc_mutex_allocate ();
#endif
autorelease_class = [NSAutoreleasePool class];
/*
* Cache some classes for quick access later.
*/
_fastCls._NSString = [NSString class];
_fastCls._NSGString = [NSGString class];
_fastCls._NSGMutableString = [NSGMutableString class];
_fastCls._NSGCString = [NSGCString class];
_fastCls._NSGMutableCString = [NSGMutableCString class];
_fastCls._NXConstantString = [NXConstantString class];
/*
* Cache some method implementations for quick access later.
*/
_fastImp._NSString_hash = (unsigned (*)())[_fastCls._NSString
instanceMethodForSelector: @selector(hash)];
_fastImp._NSGString_hash = (unsigned (*)())[_fastCls._NSGString
instanceMethodForSelector: @selector(hash)];
_fastImp._NSGString_isEqual_ = (BOOL (*)())[_fastCls._NSGString
instanceMethodForSelector: @selector(isEqual:)];
_fastImp._NSGCString_isEqual_ = (BOOL (*)())[_fastCls._NSGCString
instanceMethodForSelector: @selector(isEqual:)];
_fastBuildCache();
}
return;
}
@ -469,6 +475,11 @@ static BOOL double_release_check_enabled = NO;
+ (void) poseAsClass: (Class)aClassObject
{
class_pose_as(self, aClassObject);
/*
* We may have replaced a class in the cache, or may have replaced one
* which had cached methods, so we must rebuild the cache.
*/
_fastBuildCache();
}
- (void) doesNotRecognizeSelector: (SEL)aSelector