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:
Richard Frith-MacDonald 2010-02-26 10:25:35 +00:00
parent f088bceae8
commit e43d625338
7 changed files with 108 additions and 105 deletions

View file

@ -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>
* Source/NSNetServices.m:

View file

@ -200,7 +200,16 @@
#ifndef __has_feature
#define __has_feature(x) 0
#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_ */

View file

@ -94,10 +94,7 @@ GS_EXPORT NSString* const NSConnectionProxyCount; /* Objects received */
*/
@interface NSConnection : NSObject
{
#if GS_EXPOSE(NSConnection)
@private
id _internal;
#endif
GS_INTERNAL(NSConnection)
}
+ (NSArray*) allConnections;

View file

@ -49,10 +49,7 @@ typedef NSInteger NSOperationQueuePriority;
@interface NSOperation : NSObject
{
#if GS_EXPOSE(NSOperation)
@private
id _internal;
#endif
GS_INTERNAL(NSOperation)
}
/** Adds a dependency to the receiver.<br />

View file

@ -27,49 +27,43 @@
* their code when the class implementation is changed in new versions of the
* library.
*
* The public class MUST contain an instance variable 'id _internal;' to be
* used as a pointer to a private class containing the ivars.
* The public class MUST contain a use of the GS_INTERNAL() macro with the
* 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
* of your public class with * 'Internal' appended.
* eg. if your class is called 'MyClass' then use the following define:
* #define GSInternal MyClassInternal
*
* After including this file you can use the GS_BEGIN_INTERNAL() and
* GS_END_INTERNAL() macros to bracket the declaration of the instance
* variables.
* After including this file you can use the GS_PRIVATE_INTERNAL() macro
* to declare the private subclass used to hold real instance 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
* holding the internal instance variables, and GS_DESTROY_INTERNAL() to
* get rid of that object (only do this if '_internal' is not nil) in
* your -dealloc method.
* get rid of that object in your -dealloc method.
*
* Instance variables are referenced using the 'internal->ivar' suntax or
* 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.
*/
#define GS_BEGIN_INTERNAL(name) \
#define GS_PRIVATE_INTERNAL(name) \
@interface name ## Internal : NSObject \
{ \
@public
/* Finish declaration of internal ivars.
*/
#define GS_END_INTERNAL(name) \
@public \
GS_##name##_IVARS \
} \
@end \
@implementation name ## Internal \
@ -80,29 +74,23 @@
#define GS_CREATE_INTERNAL(name) \
_internal = [name ## Internal new];
/* Create holder for internal ivars.
/* Destroy holder for internal ivars.
*/
#define GS_DESTROY_INTERNAL(name) \
DESTROY(_internal);
if (_internal != 0) DESTROY(_internal);
#undef internal
#define internal ((GSInternal*)_internal)
#undef GSIVar
#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
*/
#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_DESTROY_INTERNAL(name)
@ -114,6 +102,6 @@ DESTROY(_internal);
#undef GSIVar
#define GSIVar(X,Y) ((X)->Y)
#endif /* !__has_feature(objc_nonfragile_abi) */
#endif /* GS_NON_FRAGILE */

View file

@ -31,7 +31,41 @@
#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
#ifdef HAVE_ALLOCA_H
@ -236,42 +270,7 @@ stringFromMsgType(int type)
#define GSInternal NSConnectionInternal
#include "GSInternal.h"
GS_BEGIN_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)
GS_PRIVATE_INTERNAL(NSConnection)
#define IisValid (internal->_isValid)
#define IindependentQueueing (internal->_independentQueueing)

View file

@ -27,8 +27,30 @@
*/
#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/NSArray.h"
#import "Foundation/NSAutoreleasePool.h"
@ -42,18 +64,7 @@
#define GSInternal NSOperationInternal
#include "GSInternal.h"
GS_BEGIN_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)
GS_PRIVATE_INTERNAL(NSOperation)
static NSArray *empty = nil;
@ -459,17 +470,7 @@ static NSArray *empty = nil;
#undef GSInternal
#define GSInternal NSOperationQueueInternal
#include "GSInternal.h"
GS_BEGIN_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)
GS_PRIVATE_INTERNAL(NSOperationQueue)
@interface NSOperationQueue (Private)