From 0fa6a5270affdc3bc62f7daadb54f98a73ac7067 Mon Sep 17 00:00:00 2001 From: mguesdon Date: Tue, 5 Apr 2005 15:54:24 +0000 Subject: [PATCH] Fixes and optimzations git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@21054 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 33 ++++++++++++ GSWeb.framework/GSWActiveImage.m | 6 +-- GSWeb.framework/GSWComponent.h | 1 + GSWeb.framework/GSWComponent.m | 54 +++++++++++++++----- GSWeb.framework/GSWDefaultAdaptor.h | 3 -- GSWeb.framework/GSWDefaultAdaptor.m | 46 ++++++++++++----- GSWeb.framework/GSWDefaultAdaptorThread.m | 16 +++--- GSWeb.framework/GSWForm.m | 23 ++++++--- GSWeb.framework/GSWGenericContainer.m | 12 +++-- GSWeb.framework/GSWHTMLDynamicElement.m | 59 +++++++++++++-------- GSWeb.framework/GSWImageButton.m | 6 +-- GSWeb.framework/GSWMailDelivery.m | 62 ++++++++++++++++++----- GSWeb.framework/GSWMultiKeyDictionary.m | 14 +++-- 13 files changed, 238 insertions(+), 97 deletions(-) diff --git a/ChangeLog b/ChangeLog index bae2354..5aba414 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,36 @@ +2005-04-05 Manuel Guesdon + * GSWeb.framework/GSWActiveImage.m: + o avoid string formatting + * GSWeb.framework/GSWImageButton.m: + o avoid string formatting + * GSWeb.framework/GSWForm.m: + o avoid string formatting + o fix https bug in -_appendCGIActionToResponse:inContext: + * GSWeb.framework/GSWGenericContainer.m: + o avoid string formatting + * GSWeb.framework/GSWHTMLDynamicElement.m: + o avoid string formatting + o IMPs optimizations + * GSWeb.framework/GSWMailDelivery.m: + o avoid string formatting + * GSWeb.framework/GSWComponent.h: + o added -logString: + * GSWeb.framework/GSWComponent.m: + o added -logString: + o implemented -logWithFormat: + o implemented -logWithFormat:arguments: + o implemented +logWithFormat: + * GSWeb.framework/GSWDefaultAdaptor.m: + o removed -logWithFormat: and +logWithFormat: + o added -workerThreadCount and -setWorkerThreadCount: + o replaced -statusLogWithFormat: calls by -statusLogString: calls + * GSWeb.framework/GSWDefaultAdaptor.h: + o removed -logWithFormat: and +logWithFormat: + * GSWeb.framework/GSWDefaultAdaptorThread.m: + o replaced -statusLogWithFormat: calls by -statusLogString: calls + * GSWeb.framework/GSWMultiKeyDictionary.m: + o better logs + 2005-04-05 Manuel Guesdon * GSWeb.framework/GSWContext.m: o add contextAndElementID caching and optimizations diff --git a/GSWeb.framework/GSWActiveImage.m b/GSWeb.framework/GSWActiveImage.m index e8a184d..33ac072 100644 --- a/GSWeb.framework/GSWActiveImage.m +++ b/GSWeb.framework/GSWActiveImage.m @@ -253,10 +253,8 @@ RCS_ID("$Id$") if (wasFormSubmitted) { NSString* nameInContext=[self nameInContext:aContext]; - NSString* formValueX=[request formValueForKey:[NSString stringWithFormat:@"%@.x", - nameInContext]]; - NSString* formValueY=[request formValueForKey:[NSString stringWithFormat:@"%@.y", - nameInContext]]; + NSString* formValueX=[request formValueForKey:[nameInContext stringByAppendingString:@".x"]]; + NSString* formValueY=[request formValueForKey:[nameInContext stringByAppendingString:@".y"]]; NSDebugMLLog(@"gswdync",@"formValueX=%@",formValueX); NSDebugMLLog(@"gswdync",@"formValueY=%@",formValueY); if (formValueX && formValueY) diff --git a/GSWeb.framework/GSWComponent.h b/GSWeb.framework/GSWComponent.h index 593110a..4b344de 100644 --- a/GSWeb.framework/GSWComponent.h +++ b/GSWeb.framework/GSWComponent.h @@ -214,6 +214,7 @@ associationsKeys:(NSArray*)associationsKeys keyPath:(id)_keyPath; -(void)_debugWithString:(NSString*)string; -(void)debugWithFormat:(NSString*)format,...; +-(void)logString:(NSString*)aString; -(void)logWithFormat:(NSString*)format,...; -(void)logWithFormat:(NSString*)format arguments:(va_list)argList; diff --git a/GSWeb.framework/GSWComponent.m b/GSWeb.framework/GSWComponent.m index 0855d52..eeb1e42 100644 --- a/GSWeb.framework/GSWComponent.m +++ b/GSWeb.framework/GSWComponent.m @@ -219,21 +219,35 @@ RCS_ID("$Id$") return aFrameworkName; }; +//-------------------------------------------------------------------- +// logString: + +-(void)logString:(NSString*)aString +{ + [[self application] logString:aString]; +}; + //-------------------------------------------------------------------- // logWithFormat: --(void)logWithFormat:(NSString*)format,... +-(void)logWithFormat:(NSString*)aFormat,... { - LOGObjectFnNotImplemented(); //TODOFN + va_list ap; + va_start(ap,aFormat); + [self logWithFormat:aFormat + arguments:ap]; + va_end(ap); }; //-------------------------------------------------------------------- // logWithFormat:arguments: --(void)logWithFormat:(NSString*)format +-(void)logWithFormat:(NSString*)aFormat arguments:(va_list)arguments { - LOGObjectFnNotImplemented(); //TODOFN + NSString* string=[NSString stringWithFormat:aFormat + arguments:arguments]; + [self logString:string]; }; //-------------------------------------------------------------------- @@ -1571,28 +1585,44 @@ associationsKeys:(NSArray*)associationsKeys }; //-------------------------------------------------------------------- --(void)debugWithFormat:(NSString*)format,... +-(void)debugWithFormat:(NSString*)aFormat,... { LOGObjectFnNotImplemented(); //TODOFN }; //-------------------------------------------------------------------- --(void)logWithFormat:(NSString*)format,... +-(void)logWithFormat:(NSString*)aFormat,... { - LOGObjectFnNotImplemented(); //TODOFN + va_list ap; + va_start(ap,aFormat); + [self logWithFormat:aFormat + arguments:ap]; + va_end(ap); }; //-------------------------------------------------------------------- --(void)logWithFormat:(NSString*)format - arguments:(va_list)argList +-(void)logWithFormat:(NSString*)aFormat + arguments:(va_list)arguments { - LOGObjectFnNotImplemented(); //TODOFN + NSString* string=[NSString stringWithFormat:aFormat + arguments:arguments]; + [self logString:string]; }; //-------------------------------------------------------------------- -+(void)logWithFormat:(NSString*)format,... ++(void)logWithFormat:(NSString*)aFormat,... { - LOGClassFnNotImplemented(); //TODOFN + va_list ap; + va_start(ap,aFormat); + [[GSWApplication application] logWithFormat:aFormat + arguments:ap]; + va_end(ap); +}; + +//-------------------------------------------------------------------- +-(void)logString:(NSString*)aString +{ + [[self application] logString:aString]; }; @end diff --git a/GSWeb.framework/GSWDefaultAdaptor.h b/GSWeb.framework/GSWDefaultAdaptor.h index fa177a8..5258832 100644 --- a/GSWeb.framework/GSWDefaultAdaptor.h +++ b/GSWeb.framework/GSWDefaultAdaptor.h @@ -55,9 +55,6 @@ GSWEB_EXPORT int iBlock; -(void)registerForEvents; -(void)unregisterForEvents; --(void)logWithFormat:(NSString*)format,...; -+(void)logWithFormat:(NSString*)format,...; - -(void)runOnce; -(BOOL)doesBusyRunOnce; -(BOOL)dispatchesRequestsConcurrently; diff --git a/GSWeb.framework/GSWDefaultAdaptor.m b/GSWeb.framework/GSWDefaultAdaptor.m index 076a7f3..9a1ff39 100644 --- a/GSWeb.framework/GSWDefaultAdaptor.m +++ b/GSWeb.framework/GSWDefaultAdaptor.m @@ -155,18 +155,6 @@ int allow_severity = LOG_INFO; DESTROY(_fileHandle); }; -//-------------------------------------------------------------------- --(void)logWithFormat:(NSString*)format,... -{ - LOGObjectFnNotImplemented(); //TODOFN -}; - -//-------------------------------------------------------------------- -+(void)logWithFormat:(NSString*)format,... -{ - LOGClassFnNotImplemented(); //TODOFN -}; - //-------------------------------------------------------------------- -(void)runOnce { @@ -201,6 +189,36 @@ int allow_severity = LOG_INFO; }; +//-------------------------------------------------------------------- +-(id)workerThreadCount +{ + return GSWIntNumber(_workerThreadCount); +}; + +//-------------------------------------------------------------------- +-(void)setWorkerThreadCount:(id)workerThreadCount +{ + if ([self tryLock]) + { + NS_DURING + { + _workerThreadCount=[workerThreadCount intValue]; + } + NS_HANDLER + { + LOGException(@"%@ (%@)", + localException, + [localException reason]); + } + NS_ENDHANDLER; + [self unlock]; + } + else + { + //TODO + }; +}; + //-------------------------------------------------------------------- -(void)setWorkerThreadCountMin:(id)workerThreadCount { @@ -457,7 +475,7 @@ int allow_severity = LOG_INFO; } else { - [GSWApplication statusLogWithFormat:@"Set Thread to wait"]; + [GSWApplication statusLogString:@"Set Thread to wait"]; NSDebugLockMLLog(@"info", @"Set Thread to wait %p", (void*)newThread); @@ -654,7 +672,7 @@ int allow_severity = LOG_INFO; #ifndef NDEBUG pool=[NSAutoreleasePool new]; GSWLogMemCF("New NSAutoreleasePool: %p",pool); - [GSWApplication statusLogWithFormat:@"Lauch waiting Thread"]; + [GSWApplication statusLogString:@"Lauch waiting Thread"]; NSDebugLockMLLog(@"info", @"Lauch waiting Thread %p", (void*)thread); diff --git a/GSWeb.framework/GSWDefaultAdaptorThread.m b/GSWeb.framework/GSWDefaultAdaptorThread.m index 50c7f29..ee2d550 100644 --- a/GSWeb.framework/GSWDefaultAdaptorThread.m +++ b/GSWeb.framework/GSWDefaultAdaptorThread.m @@ -137,7 +137,7 @@ static NSData* lineFeedData=nil; _pool=[NSAutoreleasePool new]; GSWLogMemCF("New NSAutoreleasePool: %p",_pool); #ifdef GSWDEBUG_DEEP - [GSWApplication logWithFormat:@"pool allocated!"]; + [GSWApplication logString:@"pool allocated!"]; #endif _runTS=GSWTime_now(); @@ -146,7 +146,7 @@ static NSData* lineFeedData=nil; _sendResponseTS=GSWTime_zero(); #ifdef GSWDEBUG_DEEP - [GSWApplication statusLogWithFormat:@"Thread run START"]; + [GSWApplication statusLogString:@"Thread run START"]; #endif if (_isMultiThread) { @@ -256,11 +256,11 @@ static NSData* lineFeedData=nil; _application); LOGObjectFnStop(); #ifdef DEBUG - [GSWApplication statusLogWithFormat:@"threadWillExit START"]; + [GSWApplication statusLogString:@"threadWillExit START"]; #endif [_application threadWillExit]; #ifdef DEBUG - [GSWApplication statusLogWithFormat:@"threadWillExit STOP"]; + [GSWApplication statusLogString:@"threadWillExit STOP"]; #endif if (_isMultiThread) { @@ -270,7 +270,7 @@ static NSData* lineFeedData=nil; else [self threadExited]; #ifdef DEBUG - [GSWApplication statusLogWithFormat:@"run STOP"]; + [GSWApplication statusLogString:@"run STOP"]; #endif }; @@ -785,7 +785,7 @@ withAdditionalHeaderLines:(NSArray*)addHeaders localException,[localException reason]); NSDebugMLog(@"EXCEPTION GSWDefaultAdaptorThread: sendResponse Exception:%@ (%@)", localException,[localException reason]); - [GSWApplication statusLogWithFormat:@"\nException while sending response\n"]; + [GSWApplication statusLogString:@"\nException while sending response\n"]; } NS_ENDHANDLER; @@ -813,7 +813,7 @@ withAdditionalHeaderLines:(NSArray*)addHeaders NS_DURING { [aStream writeData:responseData]; - [GSWApplication statusLogWithFormat:@"\nResponse Sent\n"]; + [GSWApplication statusLogString:@"\nResponse Sent\n"]; } NS_HANDLER { @@ -822,7 +822,7 @@ withAdditionalHeaderLines:(NSArray*)addHeaders localException,[localException reason]); NSDebugMLog(@"EXCEPTION GSWDefaultAdaptorThread: sendResponse Exception:%@ (%@)", localException,[localException reason]); - [GSWApplication statusLogWithFormat:@"\nException while sending response\n"]; + [GSWApplication statusLogString:@"\nException while sending response\n"]; } NS_ENDHANDLER; NSDebugDeepMLLog0(@"info",@"Response content Written"); diff --git a/GSWeb.framework/GSWForm.m b/GSWeb.framework/GSWForm.m index 587dde1..7babf70 100644 --- a/GSWeb.framework/GSWForm.m +++ b/GSWeb.framework/GSWForm.m @@ -1,6 +1,6 @@ /** GSWForm.m - GSWeb: Class GSWForm - Copyright (C) 1999-2004 Free Software Foundation, Inc. + Copyright (C) 1999-2005 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Jan 1999 @@ -564,8 +564,13 @@ static Class standardClass = Nil; id fragment=[_fragmentIdentifier valueInComponent:component]; NSDebugMLLog(@"gswdync",@"fragment=%@",fragment); if (fragment) - actionValue=[NSString stringWithFormat:@"%@#%@", - actionValue,fragment]; + { + if (actionValue) + actionValue=[NSStringWithObject(actionValue) stringByAppendingString:@"#"]; + else + actionValue=@"#"; + actionValue=[actionValue stringByAppendingString:NSStringWithObject(fragment)]; + }; }; NSDebugMLLog(@"gswdync",@"actionValue=%@",actionValue); //TODO emit a warning ! @@ -612,8 +617,7 @@ static Class standardClass = Nil; NSDebugMLLog(@"gswdync",@"actionString=%@",actionString); anUrl=(NSString*)[aContext directActionURLForActionNamed:actionString - queryDictionary:nil - isSecure:NO]; + queryDictionary:nil]; NSDebugMLLog(@"gswdync",@"anUrl=%@",anUrl); if (_fragmentIdentifier) @@ -621,8 +625,13 @@ static Class standardClass = Nil; id fragment=[_fragmentIdentifier valueInComponent:GSWContext_component(aContext)]; NSDebugMLLog(@"gswdync",@"fragment=%@",fragment); if (fragment) - anUrl=[NSString stringWithFormat:@"%@#%@", - anUrl,fragment]; + { + if (anUrl) + anUrl=[NSStringWithObject(anUrl) stringByAppendingString:@"#"]; + else + anUrl=@"#"; + anUrl=[anUrl stringByAppendingString:NSStringWithObject(fragment)]; + }; }; NSDebugMLLog(@"gswdync",@"anUrl=%@",anUrl); diff --git a/GSWeb.framework/GSWGenericContainer.m b/GSWeb.framework/GSWGenericContainer.m index 5bfa4d1..3ab9216 100644 --- a/GSWeb.framework/GSWGenericContainer.m +++ b/GSWeb.framework/GSWGenericContainer.m @@ -131,12 +131,14 @@ RCS_ID("$Id$") assocEnumer = [_associations keyEnumerator]; while ((currentAssocKey = [assocEnumer nextObject])) { - theValue = [[_associations objectForKey:currentAssocKey] - valueInComponent:component]; + theValue = NSStringWithObject([[_associations objectForKey:currentAssocKey] + valueInComponent:component]); - GSWResponse_appendContentString(aResponse, - ([NSString stringWithFormat:@" %@=\"%@\"", - currentAssocKey,theValue])); + GSWResponse_appendContentCharacter(aResponse,' '); + GSWResponse_appendContentString(aResponse,currentAssocKey); + GSWResponse_appendContentAsciiString(aResponse,@"=\""); + GSWResponse_appendContentString(aResponse,theValue); + GSWResponse_appendContentCharacter(aResponse,'"'); } GSWResponse_appendContentCharacter(aResponse,'>'); diff --git a/GSWeb.framework/GSWHTMLDynamicElement.m b/GSWeb.framework/GSWHTMLDynamicElement.m index 324e369..534ba77 100644 --- a/GSWeb.framework/GSWHTMLDynamicElement.m +++ b/GSWeb.framework/GSWHTMLDynamicElement.m @@ -1,6 +1,6 @@ /** GSWHTMLDynamicElement.m - GSWeb: Class GSWHTMLDynamicElement - Copyright (C) 1999-2004 Free Software Foundation, Inc. + Copyright (C) 1999-2005 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Feb 1999 @@ -35,6 +35,7 @@ RCS_ID("$Id$") #include "GSWeb.h" +#include "GSWPrivate.h" static SEL objectAtIndexSEL = NULL; @@ -808,29 +809,39 @@ attributeAssociations:(NSDictionary*)attributeAssociations { //OK GSWComponent* component=nil; - id tmpDirectActionString=nil; + NSMutableString* tmpDirectActionString=nil; id directActionNameValue=nil; id actionClassValue=nil; + IMP das_appendStringIMP=NULL; LOGObjectFnStart(); component=GSWContext_component(aContext); if (directActionName) - directActionNameValue=[directActionName valueInComponent:component]; + directActionNameValue=NSStringWithObject([directActionName valueInComponent:component]); if (actionClass) - actionClassValue=[actionClass valueInComponent:component]; + actionClassValue=NSStringWithObject([actionClass valueInComponent:component]); if (actionClassValue) { + tmpDirectActionString=(NSMutableString*) + [NSMutableString stringWithString:actionClassValue]; if (directActionNameValue) - tmpDirectActionString=[NSString stringWithFormat:@"%@/%@", - actionClassValue, - directActionNameValue]; - else - tmpDirectActionString=actionClassValue; + { + // append /directActionNameValue + GSWeb_appendStringWithImpPtr(tmpDirectActionString, + &das_appendStringIMP, + @"/"); + GSWeb_appendStringWithImpPtr(tmpDirectActionString, + &das_appendStringIMP, + directActionNameValue); + }; } else if (directActionNameValue) - tmpDirectActionString=directActionNameValue; + { + tmpDirectActionString=(NSMutableString*) + [NSMutableString stringWithString:directActionNameValue]; + } else { LOGSeriousError(@"No actionClass (for %@) and no directActionName (for %@)", @@ -898,6 +909,7 @@ attributeAssociations:(NSDictionary*)attributeAssociations NSArray* keys = nil; unsigned int count = 0; unsigned int i = 0; + // We sort keys so URL are always the same for same parameters keys=[[finalDictionary allKeys]sortedArrayUsingSelector:@selector(compare:)]; @@ -910,9 +922,19 @@ attributeAssociations:(NSDictionary*)attributeAssociations id value = [finalDictionary valueForKey:key]; NSDebugMLLog(@"gswdync",@"key=%@",key); NSDebugMLLog(@"gswdync",@"value=%@",value); - tmpDirectActionString=[tmpDirectActionString stringByAppendingFormat:@"/%@=%@", - key, - value]; + // append /key=value + GSWeb_appendStringWithImpPtr(tmpDirectActionString, + &das_appendStringIMP, + @"/"); + GSWeb_appendStringWithImpPtr(tmpDirectActionString, + &das_appendStringIMP, + NSStringWithObject(key)); + GSWeb_appendStringWithImpPtr(tmpDirectActionString, + &das_appendStringIMP, + @"="); + GSWeb_appendStringWithImpPtr(tmpDirectActionString, + &das_appendStringIMP, + NSStringWithObject(value)); }; }; }; @@ -1031,20 +1053,13 @@ in GSWHyperlink, it was GSWComponent* component=GSWContext_component(aContext); cidObject=[cidStore valueInComponent:component]; NSDebugMLog(@"cidObject=%@",cidObject); -/* if (!cidObject) - { - cidObject=(NSMutableDictionary*)[NSMutableDictionary dictionary]; - [_cidStore setValue:cidObject - inComponent:component]; - }; -*/ + if (cidObject) { if (![cidObject valueForKey:cidKeyValue]) [cidObject takeValue:cidElement forKey:cidKeyValue]; - newURL=[NSString stringWithFormat:@"cid:%@", - cidKeyValue]; + newURL=[@"cid:" stringByAppendingString:NSStringWithObject(cidKeyValue)]; }; NSDebugMLog(@"newURL=%@",newURL); }; diff --git a/GSWeb.framework/GSWImageButton.m b/GSWeb.framework/GSWImageButton.m index e02cfed..79130ca 100644 --- a/GSWeb.framework/GSWImageButton.m +++ b/GSWeb.framework/GSWImageButton.m @@ -432,10 +432,8 @@ RCS_ID("$Id$") if (wasFormSubmitted) { NSString* nameInContext=[self nameInContext:aContext]; - NSString* formValueX=[request formValueForKey:[NSString stringWithFormat:@"%@.x", - nameInContext]]; - NSString* formValueY=[request formValueForKey:[NSString stringWithFormat:@"%@.y", - nameInContext]]; + NSString* formValueX=[request formValueForKey:[nameInContext stringByAppendingString:@".x"]]; + NSString* formValueY=[request formValueForKey:[nameInContext stringByAppendingString:@".y"]]; NSDebugMLLog(@"gswdync",@"formValueX=%@",formValueX); NSDebugMLLog(@"gswdync",@"formValueY=%@",formValueY); if (formValueX && formValueY) diff --git a/GSWeb.framework/GSWMailDelivery.m b/GSWeb.framework/GSWMailDelivery.m index 45caad3..ddacfb2 100644 --- a/GSWeb.framework/GSWMailDelivery.m +++ b/GSWeb.framework/GSWMailDelivery.m @@ -1,6 +1,6 @@ /** GSWMailDelivery.m - GSWeb: Class GSWMailDelivery - Copyright (C) 1999-2003 Free Software Foundation, Inc. + Copyright (C) 1999-2005 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Feb 1999 @@ -113,7 +113,7 @@ static GSWMailDelivery *sharedInstance; plainText:(NSString*)plainTextMessage send:(BOOL)sendNow { - NSString* messageString=nil; + NSMutableString* messageString=nil; NSMutableString* toString=nil; int i=0; int count=0; @@ -133,12 +133,26 @@ static GSWMailDelivery *sharedInstance; for(i=0;i