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> 1999-03-09 Adam Fedor <fedor@gnu.org>
* Source/include/NSObjCRuntime.h: Define some OpenStep cpp vars. * 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 /* Debug logging which can be enabled/disabled by defining DEBUG
when compiling and also setting values in the mutable array when compiling and also setting values in the mutable array
that is set up by NSProcessInfo. that is set up by NSProcessInfo.
This array is initialised by NSProcess info using the
'--GNU-Debug=...' command line argument. Each command-line argument NB. The 'debug=yes' option is understood by the GNUstep make package
of that form is removed from NSProcessInfos list of arguments and the to mean that DEBUG should be defined, so you don't need to go editing
variable part (...) is added to the array. 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 For instance, to debug the NSBundle class, run your program with
'--GNU-Debug=NSBundle' '--GNU-Debug=NSBundle'
You can of course supply multiple '--GNU-Debug=...' arguments to You can of course supply multiple '--GNU-Debug=...' arguments to
output debug information on more than one thing. 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 #ifdef DEBUG
#include <Foundation/NSDebug.h> #include <Foundation/NSObjCRuntime.h>
#include <Foundation/NSProcessInfo.h> #include <Foundation/NSProcessInfo.h>
#define NSDebugLLog(level, format, args...) \ #define NSDebugLLog(level, format, args...) \
do { if ([[[NSProcessInfo processInfo] debugArray] containsObject: level]) \ do { if (GSDebugSet(level) == YES) \
NSLog(format, ## args); } while (0) NSLog(format, ## args); } while (0)
#define NSDebugLog(format, args...) \ #define NSDebugLog(format, args...) \
do { if ([[[NSProcessInfo processInfo] debugArray] containsObject: @"dflt"]) \ do { if (GSDebugSet(@"dflt") == YES) \
NSLog(format, ## args); } while (0) NSLog(format, ## args); } while (0)
#else #else
#define NSDebugLLog(level, format, args...) #define NSDebugLLog(level, format, args...)

View file

@ -32,6 +32,7 @@
@class NSMutableArray; @class NSMutableArray;
@class NSDictionary; @class NSDictionary;
@class NSData; @class NSData;
@class NSMutableSet;
@interface NSProcessInfo: NSObject @interface NSProcessInfo: NSObject
@ -48,10 +49,22 @@
/* Specifying a Process Name */ /* Specifying a Process Name */
- (void)setProcessName:(NSString *)newName; - (void)setProcessName:(NSString *)newName;
/* GNUstep extension this is a list of debug levels set using the
* --GNU-Debug=... command line option. */
- (NSMutableArray*) debugArray;
@end @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 */ #endif /* __NSProcessInfo_h_GNUSTEP_BASE_INCLUDE */

View file

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

View file

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