mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Performance optimisations - mimimise calls to malloc and avoid method despatch
overhead on deaalloc. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7925 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
cf395d3ea6
commit
379795ebe4
3 changed files with 102 additions and 36 deletions
|
@ -1,3 +1,11 @@
|
|||
2000-10-29 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSString.m: New inline string classes added to avoid calls
|
||||
to malloc in some cases. Changed all deallocation methods to call
|
||||
NSDeallocateObject() directy for efficiency.
|
||||
* Source/NSString.m: Use new inline string classes for creation of
|
||||
strings where we know the length of the data in advaance.
|
||||
|
||||
2000-10-28 Mirko Viviani <mirko.viviani@rccr.cremona.it>
|
||||
|
||||
* Headers/gnustep/base/NSBundle.h: added ivar.
|
||||
|
|
|
@ -58,7 +58,16 @@
|
|||
@end
|
||||
|
||||
/*
|
||||
* GSCSubString - concrete subclass of GSCString, that relys on the
|
||||
* GSCInlineString - concrete subclass of GSCString, that expects the
|
||||
* characterData to appear in memory immediately after the object itsself.
|
||||
*/
|
||||
@interface GSCInlineString : GSCString
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
/*
|
||||
* GSCSubString - concrete subclass of GSCString, that relies on the
|
||||
* data stored in a GSCString object.
|
||||
*/
|
||||
@interface GSCSubString : GSCString
|
||||
|
@ -76,6 +85,15 @@
|
|||
}
|
||||
@end
|
||||
|
||||
/*
|
||||
* GSUInlineString - concrete subclass of GSUString, that expects the
|
||||
* characterData to appear in memory immediately after the object itsself.
|
||||
*/
|
||||
@interface GSUInlineString : GSUString
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
/*
|
||||
* GSUSubString - concrete subclass of GSUString, that relys on the
|
||||
* data stored in a GSUString object.
|
||||
|
@ -160,9 +178,11 @@ static Class NSDataClass = 0;
|
|||
static Class NSStringClass = 0;
|
||||
static Class GSStringClass = 0;
|
||||
static Class GSCStringClass = 0;
|
||||
static Class GSCInlineStringClass = 0;
|
||||
static Class GSCSubStringClass = 0;
|
||||
static Class GSUStringClass = 0;
|
||||
static Class GSUSubStringClass = 0;
|
||||
static Class GSUInlineStringClass = 0;
|
||||
static Class GSMStringClass = 0;
|
||||
static Class NXConstantStringClass = 0;
|
||||
|
||||
|
@ -193,6 +213,8 @@ setup()
|
|||
GSStringClass = [GSString class];
|
||||
GSCStringClass = [GSCString class];
|
||||
GSUStringClass = [GSUString class];
|
||||
GSCInlineStringClass = [GSCInlineString class];
|
||||
GSUInlineStringClass = [GSUInlineString class];
|
||||
GSCSubStringClass = [GSCSubString class];
|
||||
GSUSubStringClass = [GSUSubString class];
|
||||
GSMStringClass = [GSMString class];
|
||||
|
@ -1204,7 +1226,7 @@ transmute(ivars self, NSString *aString)
|
|||
NSZoneFree(NSZoneFromPointer(_contents.c), _contents.c);
|
||||
_contents.c = 0;
|
||||
}
|
||||
[super dealloc];
|
||||
NSDeallocateObject(self);
|
||||
}
|
||||
|
||||
- (id) initWithCharactersNoCopy: (unichar*)chars
|
||||
|
@ -1300,17 +1322,10 @@ transmute(ivars self, NSString *aString)
|
|||
{
|
||||
if (NSShouldRetainWithZone(self, z) == NO)
|
||||
{
|
||||
GSCString *obj;
|
||||
NSString *obj;
|
||||
|
||||
obj = (GSCString*)NSCopyObject(self, 0, z);
|
||||
if (_contents.c != 0)
|
||||
{
|
||||
unsigned char *tmp;
|
||||
|
||||
tmp = NSZoneMalloc(z, _count);
|
||||
memcpy(tmp, _contents.c, _count);
|
||||
obj->_contents.c = tmp;
|
||||
}
|
||||
obj = (NSString*)NSAllocateObject(GSCInlineStringClass, _count, z);
|
||||
obj = [obj initWithCString: _contents.c length: _count];
|
||||
return obj;
|
||||
}
|
||||
else
|
||||
|
@ -1483,11 +1498,26 @@ transmute(ivars self, NSString *aString)
|
|||
|
||||
|
||||
|
||||
@implementation GSCInlineString
|
||||
- (id) initWithCString: (const char*)chars length: (unsigned)length
|
||||
{
|
||||
_count = length;
|
||||
_contents.c = (unsigned char*)&self[1];
|
||||
memcpy(_contents.c, chars, length);
|
||||
_flags.wide = 0;
|
||||
return self;
|
||||
}
|
||||
- (void) dealloc
|
||||
{
|
||||
NSDeallocateObject(self);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GSCSubString
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_parent);
|
||||
[super dealloc];
|
||||
NSDeallocateObject(self);
|
||||
}
|
||||
@end
|
||||
|
||||
|
@ -1559,17 +1589,10 @@ transmute(ivars self, NSString *aString)
|
|||
{
|
||||
if (NSShouldRetainWithZone(self, z) == NO)
|
||||
{
|
||||
GSUString *obj;
|
||||
NSString *obj;
|
||||
|
||||
obj = (GSUString*)NSCopyObject(self, 0, z);
|
||||
if (_contents.u != 0)
|
||||
{
|
||||
unichar *tmp;
|
||||
|
||||
tmp = NSZoneMalloc(z, _count*sizeof(unichar));
|
||||
memcpy(tmp, _contents.u, _count*sizeof(unichar));
|
||||
obj->_contents.u = tmp;
|
||||
}
|
||||
obj = (NSString*)NSAllocateObject(GSUInlineStringClass, _count*2, z);
|
||||
obj = [obj initWithCharacters: _contents.u length: _count];
|
||||
return obj;
|
||||
}
|
||||
else
|
||||
|
@ -1751,11 +1774,26 @@ transmute(ivars self, NSString *aString)
|
|||
|
||||
|
||||
|
||||
@implementation GSUInlineString
|
||||
- (id) initWithCharacters: (const unichar*)chars length: (unsigned)length
|
||||
{
|
||||
_count = length;
|
||||
_contents.u = (unichar*)&self[1];
|
||||
memcpy(_contents.u, chars, length*sizeof(unichar));
|
||||
_flags.wide = 1;
|
||||
return self;
|
||||
}
|
||||
- (void) dealloc
|
||||
{
|
||||
NSDeallocateObject(self);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GSUSubString
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_parent);
|
||||
[super dealloc];
|
||||
NSDeallocateObject(self);
|
||||
}
|
||||
@end
|
||||
|
||||
|
@ -1835,12 +1873,13 @@ transmute(ivars self, NSString *aString)
|
|||
|
||||
if (_flags.wide == 1)
|
||||
{
|
||||
copy = [GSUStringClass allocWithZone: z];
|
||||
copy = (NSString*)NSAllocateObject(GSUInlineStringClass,
|
||||
_count*sizeof(unichar), z);
|
||||
copy = [copy initWithCharacters: _contents.u length: _count];
|
||||
}
|
||||
else
|
||||
{
|
||||
copy = [GSCStringClass allocWithZone: z];
|
||||
copy = (NSString*)NSAllocateObject(GSCInlineStringClass, _count, z);
|
||||
copy = [copy initWithCString: _contents.c length: _count];
|
||||
}
|
||||
return copy;
|
||||
|
@ -1879,7 +1918,7 @@ transmute(ivars self, NSString *aString)
|
|||
self->_contents.c = 0;
|
||||
self->_zone = 0;
|
||||
}
|
||||
[super dealloc];
|
||||
NSDeallocateObject(self);
|
||||
}
|
||||
|
||||
- (void) deleteCharactersInRange: (NSRange)range
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
Date: February 1997
|
||||
|
||||
Optimisations by Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Date: October 1998
|
||||
Date: October 1998 - 2000
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
|
@ -75,6 +75,8 @@
|
|||
@class GSString;
|
||||
@class GSMString;
|
||||
@class GSUString;
|
||||
@class GSCInlineString;
|
||||
@class GSUInlineString;
|
||||
@class NSGMutableArray;
|
||||
@class NSGMutableDictionary;
|
||||
|
||||
|
@ -89,6 +91,8 @@ static Class NSMutableStringClass;
|
|||
static Class GSStringClass;
|
||||
static Class GSMStringClass;
|
||||
static Class GSUStringClass;
|
||||
static Class GSCInlineStringClass;
|
||||
static Class GSUInlineStringClass;
|
||||
|
||||
static Class plArray;
|
||||
static id (*plAdd)(id, SEL, id) = 0;
|
||||
|
@ -281,6 +285,8 @@ handle_printf_atsign (FILE *stream,
|
|||
GSStringClass = [GSString class];
|
||||
GSMStringClass = [GSMString class];
|
||||
GSUStringClass = [GSUString class];
|
||||
GSCInlineStringClass = [GSCInlineString class];
|
||||
GSUInlineStringClass = [GSUInlineString class];
|
||||
|
||||
#if HAVE_REGISTER_PRINTF_FUNCTION
|
||||
if (register_printf_function ('@',
|
||||
|
@ -324,21 +330,34 @@ handle_printf_atsign (FILE *stream,
|
|||
+ (id) stringWithCharacters: (const unichar*)chars
|
||||
length: (unsigned)length
|
||||
{
|
||||
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCharacters: chars length: length]);
|
||||
NSString *obj;
|
||||
|
||||
obj = (NSString*)NSAllocateObject(GSUInlineStringClass, length*2,
|
||||
NSDefaultMallocZone());
|
||||
obj = [obj initWithCharacters: chars length: length];
|
||||
return AUTORELEASE(obj);
|
||||
}
|
||||
|
||||
+ (id) stringWithCString: (const char*) byteString
|
||||
{
|
||||
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCString: byteString]);
|
||||
NSString *obj;
|
||||
unsigned length = strlen(byteString);
|
||||
|
||||
obj = (NSString*)NSAllocateObject(GSCInlineStringClass, length,
|
||||
NSDefaultMallocZone());
|
||||
obj = [obj initWithCString: byteString length: length];
|
||||
return AUTORELEASE(obj);
|
||||
}
|
||||
|
||||
+ (id) stringWithCString: (const char*)byteString
|
||||
length: (unsigned)length
|
||||
{
|
||||
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCString: byteString length: length]);
|
||||
NSString *obj;
|
||||
|
||||
obj = (NSString*)NSAllocateObject(GSCInlineStringClass, length,
|
||||
NSDefaultMallocZone());
|
||||
obj = [obj initWithCString: byteString length: length];
|
||||
return AUTORELEASE(obj);
|
||||
}
|
||||
|
||||
+ (id) stringWithUTF8String: (const char *)bytes
|
||||
|
@ -1410,7 +1429,7 @@ handle_printf_atsign (FILE *stream,
|
|||
prefix_len++;
|
||||
}
|
||||
}
|
||||
return [NSString stringWithCharacters: u length: prefix_len];
|
||||
return [NSStringClass stringWithCharacters: u length: prefix_len];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2450,7 +2469,7 @@ handle_printf_atsign (FILE *stream,
|
|||
if (lstat(&new_buf[8], &st) == 0)
|
||||
strcpy(new_buf, &new_buf[8]);
|
||||
}
|
||||
return [NSString stringWithCString: new_buf];
|
||||
return [NSStringClass stringWithCString: new_buf];
|
||||
#endif /* (__MINGW__) */
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue