Performance improvements when debug enabled

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3888 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-03-10 10:34:56 +00:00
parent e51cc0780e
commit d50d93ac9a
5 changed files with 145 additions and 77 deletions

View file

@ -1,3 +1,13 @@
Wed Mar 10 09:54:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/FastMap.x: FastMapNodeForKey() - special case for empty map
return 0 immediately. Fast for empty maps, marginally slower othrwise.
* Source/NSProcessInfo.m: Removed [-debugArray], Added [-debugSet],
Added GSDebugSet() function for rapid debug level testing.
* Source/include/NSProcessInfo.h: Remove [-debugArray], Add [-debugSet]
* Source/include/NSDebug.h: Rewrite NSDebugLog() and NSDebugLLog() to
be much more efficient - now minimal performance impact.
1999-03-09 Adam Fedor <fedor@gnu.org>
* Source/include/NSObjCRuntime.h: Define some OpenStep cpp vars.

View file

@ -67,23 +67,38 @@ extern const char* GSDebugAllocationList(BOOL changeFlag);
/* Debug logging which can be enabled/disabled by defining DEBUG
when compiling and also setting values in the mutable array
that is set up by NSProcessInfo.
This array is initialised by NSProcess info using the
'--GNU-Debug=...' command line argument. Each command-line argument
of that form is removed from NSProcessInfos list of arguments and the
variable part (...) is added to the array.
NB. The 'debug=yes' option is understood by the GNUstep make package
to mean that DEBUG should be defined, so you don't need to go editing
your makefiles to do it.
NSProcess initialises a set of strings that are the names of active
debug levels using the '--GNU-Debug=...' command line argument.
Each command-line argument of that form is removed from NSProcessInfos
list of arguments and the variable part (...) is added to the set.
For instance, to debug the NSBundle class, run your program with
'--GNU-Debug=NSBundle'
You can of course supply multiple '--GNU-Debug=...' arguments to
output debug information on more than one thing.
To embed debug logging in your code you use the NSDebugLLog() or
NSDebugLog() macro. NSDebugLog() is just NSDebugLLog() with the debug
level set to 'dflt'. So, to activate debug statements that use
NSDebugLog(), you supply the '--GNU-Debug=dflt' argument to your program.
You can also change the active debug levels under your programs control -
NSProcessInfo has a [-debugSet] method that returns the mutable set that
contains the active debug levels - your program can modify this set.
*/
#ifdef DEBUG
#include <Foundation/NSDebug.h>
#include <Foundation/NSObjCRuntime.h>
#include <Foundation/NSProcessInfo.h>
#define NSDebugLLog(level, format, args...) \
do { if ([[[NSProcessInfo processInfo] debugArray] containsObject: level]) \
do { if (GSDebugSet(level) == YES) \
NSLog(format, ## args); } while (0)
#define NSDebugLog(format, args...) \
do { if ([[[NSProcessInfo processInfo] debugArray] containsObject: @"dflt"]) \
do { if (GSDebugSet(@"dflt") == YES) \
NSLog(format, ## args); } while (0)
#else
#define NSDebugLLog(level, format, args...)

View file

@ -32,6 +32,7 @@
@class NSMutableArray;
@class NSDictionary;
@class NSData;
@class NSMutableSet;
@interface NSProcessInfo: NSObject
@ -48,10 +49,22 @@
/* Specifying a Process Name */
- (void)setProcessName:(NSString *)newName;
/* GNUstep extension this is a list of debug levels set using the
* --GNU-Debug=... command line option. */
- (NSMutableArray*) debugArray;
@end
#ifndef NO_GNUSTEP
@interface NSProcessInfo (GNUstep)
/* This method returns a set of debug levels set using the
* --GNU-Debug=... command line option. */
- (NSMutableSet*) debugSet;
@end
/*
* This function determines if the specified debug level is present in the
* set of active debug levels.
*/
extern BOOL GSDebugSet(NSString *level);
#endif
#endif /* __NSProcessInfo_h_GNUSTEP_BASE_INCLUDE */

View file

@ -392,6 +392,8 @@ FastMapNodeForKey(FastMapTable map, FastMapItem key)
FastMapBucket bucket;
FastMapNode node;
if (map->nodeCount == 0)
return 0;
bucket = FastMapBucketForKey(map, key);
node = FastMapNodeForKeyInBucket(bucket, key);
return node;

View file

@ -66,6 +66,7 @@
#include <string.h>
#include <Foundation/NSString.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSSet.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSException.h>
@ -129,7 +130,7 @@ static NSArray* _gnu_arguments = nil;
static NSMutableDictionary* _gnu_environment = nil;
// Array of debug levels set.
static NSMutableArray* _debug_array = nil;
static NSMutableSet* _debug_set = nil;
/*************************************************************************
*** Implementing the Libobjects main function
@ -146,19 +147,21 @@ _gnu_process_args(int argc, char *argv[], char *env[])
/* Copy the argument list */
{
NSMutableSet *mySet;
id obj_argv[argc];
int added = 0;
_debug_array = [[NSMutableArray alloc] init];
mySet = [[NSMutableSet alloc] init];
for (i = 0; i < argc; i++)
{
NSString *str = [NSString stringWithCString:argv[i]];
if ([str hasPrefix: @"--GNU-Debug="])
[_debug_array addObject: [str substringFromIndex: 12]];
[mySet addObject: [str substringFromIndex: 12]];
else
obj_argv[added++] = str;
}
_gnu_arguments = [[NSArray alloc] initWithObjects:obj_argv count:added];
_debug_set = mySet;
}
/* Copy the evironment list */
@ -223,7 +226,8 @@ _gnu_process_noobjc_args(int argc, char *argv[], char *env[])
if (_gnu_noobjc_argv == NULL)
goto error;
i = 0;
while(*argv) {
while (*argv)
{
_gnu_noobjc_argv[i] = malloc(strlen(*argv)+1);
if (_gnu_noobjc_argv[i] == NULL)
goto error;
@ -239,7 +243,8 @@ _gnu_process_noobjc_args(int argc, char *argv[], char *env[])
if (_gnu_noobjc_env == NULL)
goto error;
i = 0;
while(*env) {
while(*env)
{
_gnu_noobjc_env[i] = malloc(strlen(*env)+1);
if (_gnu_noobjc_env[i] == NULL)
goto error;
@ -260,7 +265,8 @@ static void _gnu_noobjc_free_vars(void)
char **p;
p = _gnu_noobjc_argv;
while (*p) {
while (*p)
{
free(*p);
p++;
}
@ -268,7 +274,8 @@ static void _gnu_noobjc_free_vars(void)
_gnu_noobjc_argv = 0;
p = _gnu_noobjc_env;
while (*p) {
while (*p)
{
free(*p);
p++;
}
@ -279,8 +286,10 @@ static void _gnu_noobjc_free_vars(void)
void * __gnustep_base_subinit_args__
__attribute__ ((section ("__libc_subinit"))) = &(_gnu_process_noobjc_args);
+ (void)initialize {
if (!_gnu_processName && !_gnu_arguments && !_gnu_environment) {
+ (void) initialize
{
if (!_gnu_processName && !_gnu_arguments && !_gnu_environment)
{
NSAssert(_gnu_noobjc_argv && _gnu_noobjc_env,
_GNU_MISSING_MAIN_FUNCTION_CALL);
_gnu_process_args(_gnu_noobjc_argc,_gnu_noobjc_argv,_gnu_noobjc_env);
@ -361,9 +370,9 @@ int main(int argc, char *argv[], char *env[])
return _gnu_arguments;
}
- (NSMutableArray*) debugArray
- (NSMutableSet*) debugSet
{
return _debug_array;
return _debug_set;
}
- (NSDictionary *)environment
@ -413,3 +422,22 @@ int main(int argc, char *argv[], char *env[])
@end
/*
* Function for rapid testing to see if a debug level is set.
*/
BOOL GSDebugSet(NSString *val)
{
static SEL debugSel = @selector(member:);
static IMP debugImp = 0;
if (debugImp == 0)
{
if (_debug_set == nil)
{
[[NSProcessInfo processInfo] debugSet];
}
debugImp = [_debug_set methodForSelector: debugSel];
}
return ((*debugImp)(_debug_set, debugSel, val) == val) ? YES : NO;
}