Small fixes and optimizations

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@21050 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Manuel Guesdon 2005-04-05 11:54:36 +00:00
parent 7d083127b0
commit a70d649ad1
12 changed files with 249 additions and 53 deletions

View file

@ -1,3 +1,30 @@
2005-04-05 Manuel Guesdon <mguesdon@orange-concept.com>
* GSWExtensions.framework/Makefile.preamble:
o handle GSWDEBUG in Makefile.preamble
* GSWExtensionsGSW.framework/Makefile.preamble:
o handle GSWDEBUG in Makefile.preamble
* GSWExtensionsGSW.framework/GSWCacheElement.m:
o avoid stringWithFormat for simple cases
* GSWeb.framework/GSWPrivate.h:
o new (prvate) file
* GSWeb.framework/GSWRequest.m:
o explicit use of GSWValueQualityHeaderPart to
avoid compiler warning and make code more readable
o avoid using stringWithFormat in
-_urlWithURLPrefix:requestHandlerKey:path:queryString:
o avoid appendFormat: and use cached imp appendString:
in _getFormValuesFromMultipartFormData (50% speed gain)
* GSWeb.framework/GSWRepetition.m:
o avoid stringWithFormat:
* GSWeb.framework/GSWSession.m:
o replaced some statusLogWithFormat: by statusLogString:
* GSWeb.framework/GSWApplication.h/.m:
o added status logs methods with string parameters
* GSWeb.framework/GSWConditional.m:
o avoid stringWithFormat:
* GSWeb.framework/GSWInput.m:
o ensure name binding value is a string
2005-04-04 David Wetzel <dave@turbocat.de>
* GSWeb.framework/GSWApplication.m
* GSWeb.framework/GSWRequest.m

View file

@ -43,6 +43,10 @@ else
ADDITIONAL_OBJCFLAGS := $(ADDITIONAL_OBJCFLAGS) -DUSE_BUILTIN
endif
ifeq ($(GSWDEBUG), yes)
ADDITIONAL_OBJCFLAGS := $(ADDITIONAL_OBJCFLAGS) -DGSWDEBUG
endif
ifeq ($(GSWDEBUG_MEM), yes)
ADDITIONAL_OBJCFLAGS := $(ADDITIONAL_OBJCFLAGS) -DGSWDEBUG_MEM
endif

View file

@ -133,6 +133,9 @@ static Class standardClass = Nil;
else if (_cache)
{
// Get keys associations
static NSString* keysCache[10]={ @"key0", @"key1", @"key2", @"key3", @"key4",
@"key5", @"key6", @"key7", @"key8", @"key9" };
static int keysCacheCount=10;
int keyIndex=0;
NSMutableArray* keysArray=(NSMutableArray*)[NSMutableArray array];
GSWAssociation* aKeyAssociation=nil;
@ -143,12 +146,16 @@ static Class standardClass = Nil;
aKeyAssociation=[associations objectForKey:@"key"];
if (!aKeyAssociation)
{
aKeyAssociation=[associations objectForKey:@"key0"];
aKeyAssociation=[associations objectForKey:keysCache[0]];
}
}
else if (keyIndex<keysCacheCount)
{
aKeyAssociation=[associations objectForKey:keysCache[keyIndex]];
}
else
{
aKeyAssociation=[associations objectForKey:[NSString stringWithFormat:@"key%d",keyIndex]];
aKeyAssociation=[associations objectForKey:[@"key" stringByAppendingString:GSWIntToNSString(keyIndex)]];
};
if (aKeyAssociation)
[keysArray addObject:aKeyAssociation];
@ -209,7 +216,7 @@ static Class standardClass = Nil;
{
[super setDeclarationName:declarationName];
if (declarationName && _childrenGroup)
[_childrenGroup setDeclarationName:[NSString stringWithFormat:@"%@-StaticGroup",declarationName]];
[_childrenGroup setDeclarationName:[declarationName stringByAppendingString:@"-StaticGroup"]];
};
//--------------------------------------------------------------------
@ -244,8 +251,8 @@ static Class standardClass = Nil;
NSString* elementID=nil;
NSString* uniqID=nil;
NSString* sessionID=nil;
NSString* contextAndElementIDCacheKey=nil;
NSString* elementIDCacheKey=nil;
NSMutableString* contextAndElementIDCacheKey=nil;
NSMutableString* elementIDCacheKey=nil;
GSWCache* cache=nil;
int keysCount=[_keys count];
id keys[keysCount];
@ -269,10 +276,10 @@ static Class standardClass = Nil;
_enabled,aContext);
};
uniqID=[_uniqID valueInComponent:component];
uniqID=NSStringWithObject([_uniqID valueInComponent:component]);
// Append an element to elementID So all children elementIDs will start with the same prefix
[aContext appendElementIDComponent:[NSString stringWithFormat:@"CacheElement-%@",uniqID]];
[aContext appendElementIDComponent:[@"CacheElement-" stringByAppendingString:uniqID]];
contextAndElementID=[aContext contextAndElementID];
NSDebugMLLog(@"GSWCacheElement",@"contextAndElementID=%@",contextAndElementID);
@ -309,13 +316,17 @@ static Class standardClass = Nil;
};
NSDebugMLLog(@"GSWCacheElement",@"cachedObject=%p",cachedObject);
contextAndElementIDCacheKey=[NSString stringWithFormat:@"##CONTEXT_ELEMENT_ID-%@##",
uniqID];
elementIDCacheKey=[NSString stringWithFormat:@"##ELEMENT_ID-%@##",
uniqID];
contextAndElementIDCacheKey=(NSMutableString*)[NSMutableString stringWithString:@"##CONTEXT_ELEMENT_ID-"];
[contextAndElementIDCacheKey appendString:uniqID];
[contextAndElementIDCacheKey appendString:@"##"];
elementIDCacheKey=(NSMutableString*)[NSMutableString stringWithString:@"##ELEMENT_ID--"];
[elementIDCacheKey appendString:uniqID];
[elementIDCacheKey appendString:@"##"];
if (cachedObject)
{
NSData* sessionIDData=nil;
NSLog(@"GSWCacheElement5: sessionID=%@",sessionID);
NSLog(@"GSWCacheElement5: elementID=%@",elementID);
NSLog(@"GSWCacheElement5: contextAndElementID=%@",contextAndElementID);
@ -329,9 +340,13 @@ static Class standardClass = Nil;
[cachedObject replaceOccurrencesOfData:[elementIDCacheKey dataUsingEncoding:[aResponse contentEncoding]]
withData:[elementID dataUsingEncoding:[aResponse contentEncoding]]
range:NSMakeRange(0,[cachedObject length])];
if (sessionID)
sessionIDData=[sessionID dataUsingEncoding:[aResponse contentEncoding]];
else
sessionIDData=[NSData data];
[cachedObject replaceOccurrencesOfData:[@"##SESSION_ID##" dataUsingEncoding:[aResponse contentEncoding]]
withData:[sessionID dataUsingEncoding:[aResponse contentEncoding]]
withData:sessionIDData
range:NSMakeRange(0,[cachedObject length])];
[aResponse appendContentData:cachedObject];
}
@ -367,10 +382,11 @@ static Class standardClass = Nil;
[cachedObject replaceOccurrencesOfData:[elementID dataUsingEncoding:[aResponse contentEncoding]]
withData:[elementIDCacheKey dataUsingEncoding:[aResponse contentEncoding]]
range:NSMakeRange(0,[cachedObject length])];
[cachedObject replaceOccurrencesOfData:[sessionID dataUsingEncoding:[aResponse contentEncoding]]
withData:[@"##SESSION_ID##" dataUsingEncoding:[aResponse contentEncoding]]
range:NSMakeRange(0,[cachedObject length])];
if (sessionID)
[cachedObject replaceOccurrencesOfData:[sessionID dataUsingEncoding:[aResponse contentEncoding]]
withData:[@"##SESSION_ID##" dataUsingEncoding:[aResponse contentEncoding]]
range:NSMakeRange(0,[cachedObject length])];
if (_cachedObject)
[_cachedObject setValue:cachedObject
inComponent:component];
@ -436,10 +452,10 @@ static Class standardClass = Nil;
GSWStartElement(aContext);
GSWAssertCorrectElementID(aContext);
uniqID=[_uniqID valueInComponent:[aContext component]];
uniqID=NSStringWithObject([_uniqID valueInComponent:[aContext component]]);
// Append an element to elementID So all children elementIDs will start with the same prefix
[aContext appendElementIDComponent:[NSString stringWithFormat:@"CacheElement-%@",uniqID]];
[aContext appendElementIDComponent:[@"CacheElement-" stringByAppendingString:uniqID]];
[_childrenGroup takeValuesFromRequest:aRequest
inContext:aContext];
@ -463,10 +479,10 @@ static Class standardClass = Nil;
GSWStartElement(aContext);
GSWAssertCorrectElementID(aContext);
uniqID=[_uniqID valueInComponent:[aContext component]];
uniqID=NSStringWithObject([_uniqID valueInComponent:[aContext component]]);
// Append an element to elementID So all children elementIDs will start with the same prefix
[aContext appendElementIDComponent:[NSString stringWithFormat:@"CacheElement-%@",uniqID]];
[aContext appendElementIDComponent:[@"CacheElement-" stringByAppendingString:uniqID]];
element=[_childrenGroup invokeActionForRequest:aRequest
inContext:aContext];

View file

@ -43,6 +43,10 @@ else
ADDITIONAL_OBJCFLAGS := $(ADDITIONAL_OBJCFLAGS) -DUSE_BUILTIN
endif
ifeq ($(GSWDEBUG), yes)
ADDITIONAL_OBJCFLAGS := $(ADDITIONAL_OBJCFLAGS) -DGSWDEBUG
endif
ifeq ($(GSWDEBUG_MEM), yes)
ADDITIONAL_OBJCFLAGS := $(ADDITIONAL_OBJCFLAGS) -DGSWDEBUG_MEM
endif

View file

@ -410,14 +410,24 @@ GSWEB_EXPORT BOOL WOStrictFlag;
arguments:(va_list)someArgumentsu;
-(void)debugWithFormat:(NSString*)formatString,...;
+(void)debugWithFormat:(NSString*)formatString,...;
-(void)logString:(NSString*)string;
+(void)logString:(NSString*)string;
-(void)logWithFormat:(NSString*)aFormat,...;
+(void)logWithFormat:(NSString*)aFormat,...;
-(void)logWithFormat:(NSString*)formatString_
arguments:(va_list)arguments;
-(void)logWithFormat:(NSString*)formatString
arguments:(va_list)arguments;
-(void)logErrorString:(NSString*)string;
+(void)logErrorString:(NSString*)string;
-(void)logErrorWithFormat:(NSString*)aFormat,...;
+(void)logErrorWithFormat:(NSString*)aFormat,...;
-(void)logErrorWithFormat:(NSString*)formatString
arguments:(va_list)arguments;
-(void)trace:(BOOL)flag;
-(void)traceAssignments:(BOOL)flag;
-(void)traceObjectiveCMessages:(BOOL)flag;
@ -464,14 +474,25 @@ GSWEB_EXPORT BOOL WOStrictFlag;
-(void)statusDebugWithString:(NSString*)aString;
-(void)statusDebugWithFormat:(NSString*)aFormat
arguments:(va_list)arguments;
-(void)statusDebugWithFormat:(NSString*)aFormat,...;
+(void)statusDebugWithFormat:(NSString*)aFormat,...;
-(void)statusLogString:(NSString*)string;
+(void)statusLogString:(NSString*)string;
-(void)statusLogWithFormat:(NSString*)aFormat,...;
+(void)statusLogWithFormat:(NSString*)aFormat,...;
-(void)statusLogWithFormat:(NSString*)aFormat
arguments:(va_list)arguments;
-(void)statusLogErrorString:(NSString*)string;
+(void)statusLogErrorString:(NSString*)string;
-(void)statusLogErrorWithFormat:(NSString*)aFormat,...;
+(void)statusLogErrorWithFormat:(NSString*)aFormat,...;
-(void)statusLogErrorWithFormat:(NSString*)aFormat
arguments:(va_list)arguments;
@end

View file

@ -1066,7 +1066,7 @@ int GSWApplicationMain(NSString* applicationClassName,
int languagesCount=0;
#ifdef DEBUG
GSWTime startTS=GSWTime_now();
GSWTime stopTS=nil;
GSWTime stopTS=0;
#endif
LOGObjectFnStart();
@ -3414,15 +3414,27 @@ to another instance **/
va_end(ap);
};
//--------------------------------------------------------------------
-(void)logString:(NSString*)aString
{
fputs([aString lossyCString],stderr);
fputs("\n",stderr);
fflush(stderr);
};
//--------------------------------------------------------------------
+(void)logString:(NSString*)aString
{
[GSWApp logString:aString];
};
//--------------------------------------------------------------------
-(void)logWithFormat:(NSString*)aFormat
arguments:(va_list)arguments
{
NSString* string=[NSString stringWithFormat:aFormat
arguments:arguments];
fputs([string cString],stderr);
fputs("\n",stderr);
fflush(stderr);
[self logString:string];
};
//--------------------------------------------------------------------
@ -3446,13 +3458,10 @@ to another instance **/
};
//--------------------------------------------------------------------
-(void)logErrorWithFormat:(NSString*)aFormat
arguments:(va_list)arguments
-(void)logErrorString:(NSString*)aString
{
const char* cString=NULL;
NSString* string=[NSString stringWithFormat:aFormat
arguments:arguments];
cString=[string cString];
cString=[aString lossyCString];
fputs(cString,stderr);
fputs("\n",stderr);
fflush(stderr);
@ -3463,6 +3472,21 @@ to another instance **/
#endif
};
//--------------------------------------------------------------------
+(void)logErrorString:(NSString*)aString
{
[GSWApp logErrorString:aString];
};
//--------------------------------------------------------------------
-(void)logErrorWithFormat:(NSString*)aFormat
arguments:(va_list)arguments
{
NSString* string=[NSString stringWithFormat:aFormat
arguments:arguments];
[self logErrorString:string];
};
//--------------------------------------------------------------------
//trace:
-(void)trace:(BOOL)flag
@ -3656,6 +3680,21 @@ to another instance **/
va_end(ap);
};
//--------------------------------------------------------------------
-(void)statusLogString:(NSString*)aString
{
fputs([aString lossyCString],stdout);
fputs("\n",stdout);
fflush(stdout);
[self logString:aString];
};
//--------------------------------------------------------------------
+(void)statusLogString:(NSString*)aString
{
[GSWApp statusLogString:aString];
};
//--------------------------------------------------------------------
-(void)statusLogWithFormat:(NSString*)aFormat,...
{
@ -3682,10 +3721,7 @@ to another instance **/
{
NSString* string=[NSString stringWithFormat:aFormat
arguments:arguments];
fputs([string cString],stdout);
fputs("\n",stdout);
fflush(stdout);
[self logWithFormat:@"%@",string];
[self statusLogString:string];
};
//--------------------------------------------------------------------
@ -3722,6 +3758,23 @@ to another instance **/
[self logErrorWithFormat:@"%@",string];
};
//--------------------------------------------------------------------
-(void)statusLogErrorString:(NSString*)aString
{
const char* cString=NULL;
cString=[aString lossyCString];
fputs(cString,stdout);
fputs("\n",stdout);
fflush(stdout);
[self logErrorString:aString];
};
//--------------------------------------------------------------------
+(void)statusLogErrorString:(NSString*)aString
{
[GSWApp statusLogErrorString:aString];
};
@end
//====================================================================

View file

@ -150,7 +150,7 @@ static Class standardClass = Nil;
{
[super setDeclarationName:declarationName];
if (declarationName && _childrenGroup)
[_childrenGroup setDeclarationName:[NSString stringWithFormat:@"%@-StaticGroup",declarationName]];
[_childrenGroup setDeclarationName:[declarationName stringByAppendingString:@"-StaticGroup"]];
};
//--------------------------------------------------------------------

View file

@ -132,7 +132,6 @@ static Class standardClass = Nil;
//--------------------------------------------------------------------
-(NSString*)nameInContext:(GSWContext*)context
{
//OK
GSWComponent* component=nil;
NSString* nameValue=nil;
LOGObjectFnStartC("GSWInput");
@ -140,7 +139,7 @@ static Class standardClass = Nil;
if (_name)
{
component=GSWContext_component(context);
nameValue=[_name valueInComponent:component];
nameValue=NSStringWithObject([_name valueInComponent:component]);
}
else
{

View file

@ -0,0 +1,49 @@
/** GSWPrivate.h - <title>GSWeb: Class GSWPrivate</title>
Copyright (C) 2005 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@orange-concept.com>
Date: Apr 2005
$Revision$
$Date$
This file is part of the GNUstep Web Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
</license>
**/
// $Id$
#ifndef _GSWPrivate_h__
#define _GSWPrivate_h__
/** append string to object using appendString: impPtr.
If *impPtr is NULL, the method assign it **/
static inline void GSWeb_appendStringWithImpPtr(NSMutableString* object,IMP* impPtr,NSString* string)
{
if (object)
{
if (!*impPtr)
*impPtr=[object methodForSelector:@selector(appendString:)];
(**impPtr)(object,@selector(appendString:),string);
};
};
#endif // _GSWPrivate_h__

View file

@ -140,7 +140,7 @@ static SEL setValueInComponentSEL = NULL;
{
[super setDeclarationName:declarationName];
if (declarationName && _childrenGroup)
[_childrenGroup setDeclarationName:[NSString stringWithFormat:@"%@-StaticGroup",declarationName]];
[_childrenGroup setDeclarationName:[declarationName stringByAppendingString:@"-StaticGroup"]];
};
//--------------------------------------------------------------------

View file

@ -35,6 +35,7 @@ RCS_ID("$Id$")
#include "GSWeb.h"
#include <GNUstepBase/GSMime.h>
#include "GSWInputStreamData.h"
#include "GSWPrivate.h"
//====================================================================
@implementation GSWValueQualityHeaderPart
@ -74,10 +75,12 @@ RCS_ID("$Id$")
for(i=0;i<count;i++)
{
int j=0;
NSString* value=[[qvs objectAtIndex:i] value];
GSWValueQualityHeaderPart* qv=[qvs objectAtIndex:i];
NSString* value=[qv value];
for(j=i+1;j<count;j++)
{
NSString* value2=[[qvs objectAtIndex:j] value];
GSWValueQualityHeaderPart* qv2=[qvs objectAtIndex:j];
NSString* value2=[qv2 value];
if ([value2 isEqual:value])
{
[qvs removeObjectAtIndex:j];
@ -1528,8 +1531,7 @@ RCS_ID("$Id$")
url=[self _applicationURLPrefix];
if (urlPrefix)
[url setURLPrefix:[NSString stringWithFormat:@"%@%@",
urlPrefix,[url urlPrefix]]];
[url setURLPrefix:[urlPrefix stringByAppendingString:[url urlPrefix]]];
[url setURLRequestHandlerKey:key];
[url setURLRequestHandlerPath:path];
@ -1834,11 +1836,14 @@ RCS_ID("$Id$")
NSMutableString* headersString=[NSMutableString string];
NSDictionary* headers=nil;
NSEnumerator* enumerator=nil;
LOGObjectFnStart();
IMP headersString_appendStringIMP=NULL;
NSStringEncoding e;
LOGObjectFnStart();
formValues=(NSMutableDictionary*)[NSMutableDictionary dictionary];
// Append Each Header
headers=[self headers];
enumerator=[headers keyEnumerator];
while((key=[enumerator nextObject]))
@ -1847,13 +1852,31 @@ RCS_ID("$Id$")
int i=0;
int count=[value count];
for(i=0;i<count;i++)
[headersString appendFormat:@"%@: %@\n",
key,[value objectAtIndex:i]];
{
// append "key: value\n" to headersString
GSWeb_appendStringWithImpPtr(headersString,
&headersString_appendStringIMP,
key);
GSWeb_appendStringWithImpPtr(headersString,
&headersString_appendStringIMP,
@": ");
GSWeb_appendStringWithImpPtr(headersString,
&headersString_appendStringIMP,
[value objectAtIndex:i]);
GSWeb_appendStringWithImpPtr(headersString,
&headersString_appendStringIMP,
@"\n");
};
};
[headersString appendString:@"\n"];
// Append \n to specify headers end.
GSWeb_appendStringWithImpPtr(headersString,
&headersString_appendStringIMP,
@"\n");
NSDebugMLLog(@"requests",@"headersString=[\n%@\n]",headersString);
// headersData=[headersString dataUsingEncoding:[self formValueEncoding]];
// NSASCIIStringEncoding should be ok dave@turbocat.de
// headersData=[headersString dataUsingEncoding:[self formValueEncoding]];
// NSASCIIStringEncoding should be ok dave@turbocat.de
headersData=[headersString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
parser=[GSMimeParser mimeParser];
[parser parse:headersData];

View file

@ -794,7 +794,7 @@ RCS_ID("$Id$")
{
id deletePage=nil;
NSString* deleteContextID=nil;
[GSWApplication statusLogWithFormat:@"Deleting permanent cached Page"];
[GSWApplication statusLogString:@"Deleting permanent cached Page"];
deleteContextID=[_permanentContextIDArray objectAtIndex:0];
GSWLogAssertGood(deleteContextID);
RETAIN(deleteContextID); // We'll remove it from array
@ -1214,7 +1214,7 @@ extern id gcObjectsToBeVisited;
RETAIN(deleteContextID);
GSWLogAssertGood(deleteContextID);
[GSWApplication statusLogWithFormat:@"Deleting cached Page"];
[GSWApplication statusLogString:@"Deleting cached Page"];
//NSLog(@"DD contextArray class=%@",[contextArray class]);
//NSLog(@"CC contextArray count=%d",[contextArray count]);
@ -1244,7 +1244,7 @@ extern id gcObjectsToBeVisited;
RETAIN(deleteContextID);
GSWLogAssertGood(deleteContextID);
[GSWApplication statusLogWithFormat:@"Deleting cached Page"];
[GSWApplication statusLogString:@"Deleting cached Page"];
//NSLog(@"EE aContextArray class=%@",[aContextArray class]);
//NSLog(@"EE aContextArray count=%d",[aContextArray count]);