mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-07 15:01:10 +00:00
improve instance variable hiding
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29779 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3cb9f2549b
commit
837c59689b
7 changed files with 108 additions and 105 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
2010-02-26 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSOperation.m:
|
||||||
|
* Source/GSInternal.h:
|
||||||
|
* Source/NSConnection.m:
|
||||||
|
* Headers/Foundation/NSConnection.h:
|
||||||
|
* Headers/Foundation/NSOperation.h:
|
||||||
|
* Headers/Additions/GNUstepBase/GSVersionMacros.h:
|
||||||
|
Rework hiding of instance variables for big classes (lots of ivars)
|
||||||
|
where we expect the class lifetime to be long enough that it makes
|
||||||
|
sense to hod the ivars in a private subclass.
|
||||||
|
|
||||||
2010-02-26 Richard Frith-Macdonald <rfm@gnu.org>
|
2010-02-26 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSNetServices.m:
|
* Source/NSNetServices.m:
|
||||||
|
|
|
@ -200,7 +200,16 @@
|
||||||
#ifndef __has_feature
|
#ifndef __has_feature
|
||||||
#define __has_feature(x) 0
|
#define __has_feature(x) 0
|
||||||
#endif
|
#endif
|
||||||
#define GS_EXPOSE(X) \
|
|
||||||
((!__has_feature(objc_nonfragile_abi) && !__has_feature(objc_nonfragile_abi2)) || defined(EXPOSE_##X##_IVARS))
|
#define GS_NONFRAGILE \
|
||||||
|
(__has_feature(objc_nonfragile_abi) || __has_feature(objc_nonfragile_abi2))
|
||||||
|
|
||||||
|
#define GS_EXPOSE(X) (!GS_NONFRAGILE || defined(EXPOSE_##X##_IVARS))
|
||||||
|
|
||||||
|
#if GS_NONFRAGILE
|
||||||
|
# define GS_INTERNAL(X) @public GS_##X##_IVARS
|
||||||
|
#else
|
||||||
|
# define GS_INTERNAL(X) @private id _internal;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __GNUSTEP_GSVERSIONMACROS_H_INCLUDED_ */
|
#endif /* __GNUSTEP_GSVERSIONMACROS_H_INCLUDED_ */
|
||||||
|
|
|
@ -94,10 +94,7 @@ GS_EXPORT NSString* const NSConnectionProxyCount; /* Objects received */
|
||||||
*/
|
*/
|
||||||
@interface NSConnection : NSObject
|
@interface NSConnection : NSObject
|
||||||
{
|
{
|
||||||
#if GS_EXPOSE(NSConnection)
|
GS_INTERNAL(NSConnection)
|
||||||
@private
|
|
||||||
id _internal;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray*) allConnections;
|
+ (NSArray*) allConnections;
|
||||||
|
|
|
@ -49,10 +49,7 @@ typedef NSInteger NSOperationQueuePriority;
|
||||||
|
|
||||||
@interface NSOperation : NSObject
|
@interface NSOperation : NSObject
|
||||||
{
|
{
|
||||||
#if GS_EXPOSE(NSOperation)
|
GS_INTERNAL(NSOperation)
|
||||||
@private
|
|
||||||
id _internal;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds a dependency to the receiver.<br />
|
/** Adds a dependency to the receiver.<br />
|
||||||
|
|
|
@ -27,49 +27,43 @@
|
||||||
* their code when the class implementation is changed in new versions of the
|
* their code when the class implementation is changed in new versions of the
|
||||||
* library.
|
* library.
|
||||||
*
|
*
|
||||||
* The public class MUST contain an instance variable 'id _internal;' to be
|
* The public class MUST contain a use of the GS_INTERNAL() macro with the
|
||||||
* used as a pointer to a private class containing the ivars.
|
* class name as it's argument.
|
||||||
|
*
|
||||||
|
* Before including the header file containing the public class declaration,
|
||||||
|
* you must define GS_X_IVARS (where X is the class name) to be the
|
||||||
|
* list of actual instance variable declarations for the class.
|
||||||
*
|
*
|
||||||
* Before including this file, you must define 'GSInternal' to be the name
|
* Before including this file, you must define 'GSInternal' to be the name
|
||||||
* of your public class with * 'Internal' appended.
|
* of your public class with * 'Internal' appended.
|
||||||
* eg. if your class is called 'MyClass' then use the following define:
|
* eg. if your class is called 'MyClass' then use the following define:
|
||||||
* #define GSInternal MyClassInternal
|
* #define GSInternal MyClassInternal
|
||||||
*
|
*
|
||||||
* After including this file you can use the GS_BEGIN_INTERNAL() and
|
* After including this file you can use the GS_PRIVATE_INTERNAL() macro
|
||||||
* GS_END_INTERNAL() macros to bracket the declaration of the instance
|
* to declare the private subclass used to hold real instance variables.
|
||||||
* variables.
|
* The argument to this macro is the public class name (the GS_X_IVARS
|
||||||
|
* list must also be defined).
|
||||||
*
|
*
|
||||||
* You use GS_CREATE_INTERNAL() in your intialiser to create the object
|
* You use GS_CREATE_INTERNAL() in your intialiser to create the object
|
||||||
* holding the internal instance variables, and GS_DESTROY_INTERNAL() to
|
* holding the internal instance variables, and GS_DESTROY_INTERNAL() to
|
||||||
* get rid of that object (only do this if '_internal' is not nil) in
|
* get rid of that object in your -dealloc method.
|
||||||
* your -dealloc method.
|
|
||||||
*
|
*
|
||||||
* Instance variables are referenced using the 'internal->ivar' suntax or
|
* Instance variables are referenced using the 'internal->ivar' suntax or
|
||||||
* the GSIV(classname,object,ivar) macro.
|
* the GSIV(classname,object,ivar) macro.
|
||||||
*
|
*
|
||||||
* ARGH FIXME ... the following idea doesn't work ... need to rethink/rwrite.
|
|
||||||
*
|
|
||||||
* If built with CLANG, with support for non-fragile instance variables,
|
|
||||||
* rather than GCC, the compiler/runtime can simply declare instance variables
|
|
||||||
* within the implementation file so that they are not part of the public ABI,
|
|
||||||
* in which case the macros here mostly reduce to nothing and the generated
|
|
||||||
* code can be much more efficient.
|
|
||||||
*/
|
*/
|
||||||
#if 1 || !__has_feature(objc_nonfragile_abi)
|
#if !GS_NON_FRAGILE
|
||||||
|
|
||||||
/* Code for when we don't have non-fragine instance variables
|
/* Code for when we don't have non-fragile instance variables
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Start declaration of internal ivars.
|
/* Start declaration of internal ivars.
|
||||||
*/
|
*/
|
||||||
#define GS_BEGIN_INTERNAL(name) \
|
#define GS_PRIVATE_INTERNAL(name) \
|
||||||
@interface name ## Internal : NSObject \
|
@interface name ## Internal : NSObject \
|
||||||
{ \
|
{ \
|
||||||
@public
|
@public \
|
||||||
|
GS_##name##_IVARS \
|
||||||
/* Finish declaration of internal ivars.
|
|
||||||
*/
|
|
||||||
#define GS_END_INTERNAL(name) \
|
|
||||||
} \
|
} \
|
||||||
@end \
|
@end \
|
||||||
@implementation name ## Internal \
|
@implementation name ## Internal \
|
||||||
|
@ -80,29 +74,23 @@
|
||||||
#define GS_CREATE_INTERNAL(name) \
|
#define GS_CREATE_INTERNAL(name) \
|
||||||
_internal = [name ## Internal new];
|
_internal = [name ## Internal new];
|
||||||
|
|
||||||
/* Create holder for internal ivars.
|
/* Destroy holder for internal ivars.
|
||||||
*/
|
*/
|
||||||
#define GS_DESTROY_INTERNAL(name) \
|
#define GS_DESTROY_INTERNAL(name) \
|
||||||
DESTROY(_internal);
|
if (_internal != 0) DESTROY(_internal);
|
||||||
|
|
||||||
#undef internal
|
#undef internal
|
||||||
#define internal ((GSInternal*)_internal)
|
#define internal ((GSInternal*)_internal)
|
||||||
#undef GSIVar
|
#undef GSIVar
|
||||||
#define GSIVar(X,Y) (((GSInternal*)(X->_internal))->Y)
|
#define GSIVar(X,Y) (((GSInternal*)(X->_internal))->Y)
|
||||||
|
|
||||||
#else /* !__has_feature(objc_nonfragile_abi) */
|
#else /* GS_NON_FRAGILE */
|
||||||
|
|
||||||
/* We have support for non-fragile ivars
|
/* We have support for non-fragile ivars
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define GS_BEGIN_INTERNAL(name) @interface name () {
|
#define GS_PRIVATE_INTERNAL(name)
|
||||||
|
|
||||||
/* Finish declaration of internal ivars.
|
|
||||||
*/
|
|
||||||
#define GS_END_INTERNAL(name) } @end
|
|
||||||
|
|
||||||
/* Create holder for internal ivars (nothing to do).
|
|
||||||
*/
|
|
||||||
#define GS_CREATE_INTERNAL(name)
|
#define GS_CREATE_INTERNAL(name)
|
||||||
|
|
||||||
#define GS_DESTROY_INTERNAL(name)
|
#define GS_DESTROY_INTERNAL(name)
|
||||||
|
@ -114,6 +102,6 @@ DESTROY(_internal);
|
||||||
#undef GSIVar
|
#undef GSIVar
|
||||||
#define GSIVar(X,Y) ((X)->Y)
|
#define GSIVar(X,Y) ((X)->Y)
|
||||||
|
|
||||||
#endif /* !__has_feature(objc_nonfragile_abi) */
|
#endif /* GS_NON_FRAGILE */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,41 @@
|
||||||
|
|
||||||
#import "common.h"
|
#import "common.h"
|
||||||
|
|
||||||
#define EXPOSE_NSConnection_IVARS 1
|
#define GS_NSConnection_IVARS \
|
||||||
|
BOOL _isValid; \
|
||||||
|
BOOL _independentQueueing; \
|
||||||
|
BOOL _authenticateIn; \
|
||||||
|
BOOL _authenticateOut; \
|
||||||
|
BOOL _multipleThreads; \
|
||||||
|
BOOL _shuttingDown; \
|
||||||
|
BOOL _useKeepalive; \
|
||||||
|
BOOL _keepaliveWait; \
|
||||||
|
NSPort *_receivePort; \
|
||||||
|
NSPort *_sendPort; \
|
||||||
|
unsigned _requestDepth; \
|
||||||
|
unsigned _messageCount; \
|
||||||
|
unsigned _reqOutCount; \
|
||||||
|
unsigned _reqInCount; \
|
||||||
|
unsigned _repOutCount; \
|
||||||
|
unsigned _repInCount; \
|
||||||
|
GSIMapTable _localObjects; \
|
||||||
|
GSIMapTable _localTargets; \
|
||||||
|
GSIMapTable _remoteProxies; \
|
||||||
|
GSIMapTable _replyMap; \
|
||||||
|
NSTimeInterval _replyTimeout; \
|
||||||
|
NSTimeInterval _requestTimeout; \
|
||||||
|
NSMutableArray *_requestModes; \
|
||||||
|
NSMutableArray *_runLoops; \
|
||||||
|
NSMutableArray *_requestQueue; \
|
||||||
|
id _delegate; \
|
||||||
|
NSRecursiveLock *_refGate; \
|
||||||
|
NSMutableArray *_cachedDecoders; \
|
||||||
|
NSMutableArray *_cachedEncoders; \
|
||||||
|
NSString *_remoteName; \
|
||||||
|
NSString *_registeredName; \
|
||||||
|
NSPortNameServer *_nameServer; \
|
||||||
|
int _lastKeepalive;
|
||||||
|
|
||||||
#define EXPOSE_NSDistantObject_IVARS 1
|
#define EXPOSE_NSDistantObject_IVARS 1
|
||||||
|
|
||||||
#ifdef HAVE_ALLOCA_H
|
#ifdef HAVE_ALLOCA_H
|
||||||
|
@ -236,42 +270,7 @@ stringFromMsgType(int type)
|
||||||
|
|
||||||
#define GSInternal NSConnectionInternal
|
#define GSInternal NSConnectionInternal
|
||||||
#include "GSInternal.h"
|
#include "GSInternal.h"
|
||||||
GS_BEGIN_INTERNAL(NSConnection)
|
GS_PRIVATE_INTERNAL(NSConnection)
|
||||||
BOOL _isValid;
|
|
||||||
BOOL _independentQueueing;
|
|
||||||
BOOL _authenticateIn;
|
|
||||||
BOOL _authenticateOut;
|
|
||||||
BOOL _multipleThreads;
|
|
||||||
BOOL _shuttingDown;
|
|
||||||
BOOL _useKeepalive;
|
|
||||||
BOOL _keepaliveWait;
|
|
||||||
NSPort *_receivePort;
|
|
||||||
NSPort *_sendPort;
|
|
||||||
unsigned _requestDepth;
|
|
||||||
unsigned _messageCount;
|
|
||||||
unsigned _reqOutCount;
|
|
||||||
unsigned _reqInCount;
|
|
||||||
unsigned _repOutCount;
|
|
||||||
unsigned _repInCount;
|
|
||||||
GSIMapTable _localObjects;
|
|
||||||
GSIMapTable _localTargets;
|
|
||||||
GSIMapTable _remoteProxies;
|
|
||||||
GSIMapTable _replyMap;
|
|
||||||
NSTimeInterval _replyTimeout;
|
|
||||||
NSTimeInterval _requestTimeout;
|
|
||||||
NSMutableArray *_requestModes;
|
|
||||||
NSMutableArray *_runLoops;
|
|
||||||
NSMutableArray *_requestQueue;
|
|
||||||
id _delegate;
|
|
||||||
NSRecursiveLock *_refGate;
|
|
||||||
NSMutableArray *_cachedDecoders;
|
|
||||||
NSMutableArray *_cachedEncoders;
|
|
||||||
NSString *_remoteName;
|
|
||||||
NSString *_registeredName;
|
|
||||||
NSPortNameServer *_nameServer;
|
|
||||||
int _lastKeepalive;
|
|
||||||
GS_END_INTERNAL(NSConnection)
|
|
||||||
|
|
||||||
|
|
||||||
#define IisValid (internal->_isValid)
|
#define IisValid (internal->_isValid)
|
||||||
#define IindependentQueueing (internal->_independentQueueing)
|
#define IindependentQueueing (internal->_independentQueueing)
|
||||||
|
|
|
@ -27,8 +27,30 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "common.h"
|
#import "common.h"
|
||||||
#define EXPOSE_NSOperation_IVARS 1
|
|
||||||
#define EXPOSE_NSOperationQueue_IVARS 1
|
#define GS_NSOperation_IVARS \
|
||||||
|
NSRecursiveLock *lock; \
|
||||||
|
NSConditionLock *cond; \
|
||||||
|
NSOperationQueuePriority priority; \
|
||||||
|
double threadPriority; \
|
||||||
|
BOOL cancelled; \
|
||||||
|
BOOL concurrent; \
|
||||||
|
BOOL executing; \
|
||||||
|
BOOL finished; \
|
||||||
|
BOOL ready; \
|
||||||
|
NSMutableArray *dependencies;
|
||||||
|
|
||||||
|
#define GS_NSOperationQueue_IVARS \
|
||||||
|
NSRecursiveLock *lock; \
|
||||||
|
NSConditionLock *cond; \
|
||||||
|
NSMutableArray *operations; \
|
||||||
|
NSMutableArray *waiting; \
|
||||||
|
NSString *name; \
|
||||||
|
BOOL suspended; \
|
||||||
|
NSInteger threads; \
|
||||||
|
NSInteger idle; \
|
||||||
|
NSInteger count;
|
||||||
|
|
||||||
#import "Foundation/NSOperation.h"
|
#import "Foundation/NSOperation.h"
|
||||||
#import "Foundation/NSArray.h"
|
#import "Foundation/NSArray.h"
|
||||||
#import "Foundation/NSAutoreleasePool.h"
|
#import "Foundation/NSAutoreleasePool.h"
|
||||||
|
@ -42,18 +64,7 @@
|
||||||
|
|
||||||
#define GSInternal NSOperationInternal
|
#define GSInternal NSOperationInternal
|
||||||
#include "GSInternal.h"
|
#include "GSInternal.h"
|
||||||
GS_BEGIN_INTERNAL(NSOperation)
|
GS_PRIVATE_INTERNAL(NSOperation)
|
||||||
NSRecursiveLock *lock;
|
|
||||||
NSConditionLock *cond;
|
|
||||||
NSOperationQueuePriority priority;
|
|
||||||
double threadPriority;
|
|
||||||
BOOL cancelled;
|
|
||||||
BOOL concurrent;
|
|
||||||
BOOL executing;
|
|
||||||
BOOL finished;
|
|
||||||
BOOL ready;
|
|
||||||
NSMutableArray *dependencies;
|
|
||||||
GS_END_INTERNAL(NSOperation)
|
|
||||||
|
|
||||||
static NSArray *empty = nil;
|
static NSArray *empty = nil;
|
||||||
|
|
||||||
|
@ -459,17 +470,7 @@ static NSArray *empty = nil;
|
||||||
#undef GSInternal
|
#undef GSInternal
|
||||||
#define GSInternal NSOperationQueueInternal
|
#define GSInternal NSOperationQueueInternal
|
||||||
#include "GSInternal.h"
|
#include "GSInternal.h"
|
||||||
GS_BEGIN_INTERNAL(NSOperationQueue)
|
GS_PRIVATE_INTERNAL(NSOperationQueue)
|
||||||
NSRecursiveLock *lock;
|
|
||||||
NSConditionLock *cond;
|
|
||||||
NSMutableArray *operations;
|
|
||||||
NSMutableArray *waiting;
|
|
||||||
NSString *name;
|
|
||||||
BOOL suspended;
|
|
||||||
NSInteger threads; // number of threads allocated
|
|
||||||
NSInteger idle; // threads waiting for an op to do
|
|
||||||
NSInteger count; // max executing operations
|
|
||||||
GS_END_INTERNAL(NSOperationQueue)
|
|
||||||
|
|
||||||
|
|
||||||
@interface NSOperationQueue (Private)
|
@interface NSOperationQueue (Private)
|
||||||
|
|
Loading…
Reference in a new issue