o use of IMPs for speed

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@19955 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Manuel Guesdon 2004-09-01 14:41:25 +00:00
parent ce45ebf3d4
commit e11d0c51d8
2 changed files with 58 additions and 10 deletions

View file

@ -41,7 +41,9 @@
NSStringEncoding _contentEncoding;
NSDictionary* _userInfo;
NSMutableString* _contentString;
IMP _contentStringASImp;
NSMutableData* _contentData;
IMP _contentDataADImp;
#ifndef NO_GNUSTEP
NSMutableArray* _cachesStack; // Cache Stacks
#endif

View file

@ -38,6 +38,9 @@ RCS_ID("$Id$")
static NSStringEncoding globalDefaultEncoding=NSISOLatin1StringEncoding;
static NSString* globalDefaultURLEncoding=nil;
static SEL appendStringSel = NULL;
static SEL appendDataSel = NULL;
//====================================================================
#ifndef NO_GNUSTEP
@ -50,9 +53,28 @@ static NSString* globalDefaultURLEncoding=nil;
#endif
#define assertContentStringASImp(); \
{ if (!_contentStringASImp) { \
_contentStringASImp=[_contentString \
methodForSelector:appendStringSel]; }; };
#define assertContentDataADImp(); \
{ if (!_contentDataADImp) { \
_contentDataADImp=[_contentData \
methodForSelector:appendDataSel]; }; };
//====================================================================
@implementation GSWMessage
+ (void) initialize
{
if (self == [GSWMessage class])
{
appendStringSel = @selector(appendString:);
appendDataSel = @selector(appendData:);
};
};
//--------------------------------------------------------------------
// init
@ -111,9 +133,11 @@ static NSString* globalDefaultURLEncoding=nil;
DESTROY(clone->_contentString);
clone->_contentString=[_contentString mutableCopyWithZone:zone];
clone->_contentStringASImp=NULL;
DESTROY(clone->_contentData);
clone->_contentData=[_contentData mutableCopyWithZone:zone];
clone->_contentDataADImp=NULL;
#ifndef NO_GNUSTEP
DESTROY(clone->_cachesStack);
@ -337,10 +361,16 @@ static NSString* globalDefaultURLEncoding=nil;
-(void)_initContentData
{
LOGObjectFnStart();
DESTROY(_contentString);
DESTROY(_contentData);
_contentString=[NSMutableString new];
_contentStringASImp=NULL;
_contentData=[NSMutableData new];
_contentDataADImp=NULL;
LOGObjectFnStop();
};
@ -425,7 +455,8 @@ static NSString* globalDefaultURLEncoding=nil;
tmpString=[[[NSString alloc]initWithData:contentData
encoding:[self contentEncoding]]
autorelease];
[_contentString appendString:tmpString];
assertContentStringASImp();
(*_contentStringASImp)(_contentString,appendStringSel,tmpString);
#ifndef NO_GNUSTEP
if (_cachesStack)
@ -436,11 +467,13 @@ static NSString* globalDefaultURLEncoding=nil;
{
if ([_contentData length]>0)
{
[_contentData appendData:contentData];
assertContentDataADImp();
(*_contentDataADImp)(_contentData,appendDataSel,contentData);
}
else
{
_contentData = (NSMutableData*)[contentData mutableCopy];
_contentDataADImp = NULL;
};
#ifndef NO_GNUSTEP
@ -456,7 +489,9 @@ static NSString* globalDefaultURLEncoding=nil;
-(void)_appendContentAsciiString:(NSString*)aString
{
NSString* string=nil;
LOGObjectFnStart();
NSAssert2([_contentData length]==0,
@"Try to append string but content is data. \nString: '%@'\nData: '%@'",
string,
@ -468,12 +503,14 @@ static NSString* globalDefaultURLEncoding=nil;
string=[NSString stringWithObject:aString];
NSDebugMLLog(@"low",@"string:%@",string);
[_contentString appendString:string];
assertContentStringASImp();
(*_contentStringASImp)(_contentString,appendStringSel,string);
#ifndef NO_GNUSTEP
if (_cachesStack)
[self _cacheAppendString:string];
#endif
LOGObjectFnStop();
};
@ -483,7 +520,9 @@ static NSString* globalDefaultURLEncoding=nil;
-(void)_appendContentCharacter:(char)aChar
{
NSString* string=nil;
LOGObjectFnStart();
NSDebugMLLog(@"low",@"aChar:%c",aChar);
NSAssert2([_contentData length]==0,
@"Try to append string but content is data. \naChar: '%c'\nData: '%@'",
@ -492,9 +531,11 @@ static NSString* globalDefaultURLEncoding=nil;
encoding:[self contentEncoding]]
autorelease]);
string=[NSString stringWithFormat:@"%c",aChar];
string=[NSString stringWithCString:&aChar
length:1];
[_contentString appendString:string];
assertContentStringASImp();
(*_contentStringASImp)(_contentString,appendStringSel,string);
#ifndef NO_GNUSTEP
if (_cachesStack)
@ -508,6 +549,7 @@ static NSString* globalDefaultURLEncoding=nil;
-(void)appendContentString:(NSString*)string
{
LOGObjectFnStart();
NSDebugMLLog(@"low",@"string:%@",string);
NSAssert2([_contentData length]==0,
@"Try to append string but content is data. \n"
@ -516,10 +558,10 @@ static NSString* globalDefaultURLEncoding=nil;
[[[NSString alloc]initWithData:_contentData
encoding:[self contentEncoding]]
autorelease]);
if (string)
{
[_contentString appendString:string];
}
assertContentStringASImp();
(*_contentStringASImp)(_contentString,appendStringSel,string);
#ifndef NO_GNUSTEP
if (_cachesStack)
[self _cacheAppendString:string];
@ -652,7 +694,11 @@ static NSString* globalDefaultURLEncoding=nil;
{
#ifndef NDEBUG
if (GSDebugSet(@"debugComments") == YES)
[self appendContentString:[NSString stringWithFormat:@"\n<!-- %@ -->\n",aString]];
{
[self appendContentString:@"\n<!-- "];
[self appendContentString:aString];
[self appendContentString:@" -->\n"];
};
#endif
};