Performance improvmentes for coding.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3093 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-10-21 11:56:58 +00:00
parent 5049319df5
commit 0a4d30b935
9 changed files with 814 additions and 600 deletions

View file

@ -112,8 +112,16 @@
* object - or they will find it's buffer disappearing unexpectedly. * object - or they will find it's buffer disappearing unexpectedly.
* Once you have used this method, you own the malloced data and are * Once you have used this method, you own the malloced data and are
* responsible for freeing it. * responsible for freeing it.
* NB. While this buffer is guaranteed to be freeable by NSZoneFree(),
* it's not necessarily safe to pass it to free()/objc_free() and
* friends. If you wish to pass the buffer to code that might use
* free() or realloc(), you should use the
* -relinquishAllocatedBytesFromZone: method instead - this method
* will only relinquich the buffer if it was allocated from the
* specified zone (a zone of 0 disables this checking).
*/ */
- (void*) relinquishAllocatedBytes; - (void*) relinquishAllocatedBytes;
- (void*) relinquishAllocatedBytesFromZone: (NSZone*)aZone;
@end @end

View file

@ -264,6 +264,7 @@ enum {
#endif #endif
#ifndef NO_GNUSTEP #ifndef NO_GNUSTEP
- (BOOL) boolValue;
- (NSString*) descriptionForPropertyList; - (NSString*) descriptionForPropertyList;
- (id) initWithCharactersNoCopy: (unichar*)chars - (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length length: (unsigned int)length

File diff suppressed because it is too large Load diff

View file

@ -28,7 +28,6 @@
#include <gnustep/base/behavior.h> #include <gnustep/base/behavior.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSPortCoder.h> #include <Foundation/NSPortCoder.h>
#include <gnustep/base/Coding.h>
@interface NSGArray : NSArray @interface NSGArray : NSArray
{ {
@ -105,46 +104,28 @@
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
unsigned i; [aCoder encodeValueOfObjCType: @encode(unsigned)
at: &_count];
[(id<Encoding>)aCoder encodeValueOfCType: @encode(unsigned) if (_count > 0) {
at: &_count [aCoder encodeArrayOfObjCType: @encode(id)
withName: @"Array content count"]; count: _count
at: _contents_array];
for (i = 0; i < _count; i++) {
[(id<Encoding>)aCoder encodeObject: _contents_array[i]
withName: @"Array content"];
} }
} }
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
unsigned count; [aCoder decodeValueOfObjCType: @encode(unsigned)
at: &_count];
#if 0 if (_count > 0) {
unsigned dummy; _contents_array = NSZoneCalloc([self zone], _count, sizeof(id));
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
at: &dummy
withName: NULL];
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
at: &dummy
withName: NULL];
#endif
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
at: &count
withName: NULL];
if (count > 0) {
_contents_array = NSZoneMalloc([self zone], sizeof(id)*count);
if (_contents_array == 0) { if (_contents_array == 0) {
[NSException raise: NSMallocException [NSException raise: NSMallocException
format: @"Unable to make array"]; format: @"Unable to make array"];
} }
while (_count < count) { [aCoder decodeArrayOfObjCType: @encode(id)
[(id<Decoding>)aCoder decodeObjectAt: &_contents_array[_count++] count: _count
withName: NULL]; at: _contents_array];
}
} }
return self; return self;
} }
@ -245,16 +226,17 @@
{ {
unsigned count; unsigned count;
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned) [aCoder decodeValueOfObjCType: @encode(unsigned)
at: &count at: &count];
withName: NULL];
if ([self initWithCapacity: count] == nil) { if ([self initWithCapacity: count] == nil) {
[NSException raise: NSMallocException [NSException raise: NSMallocException
format: @"Unable to make array"]; format: @"Unable to make array"];
} }
while (_count < count) { if (count > 0) {
[(id<Decoding>)aCoder decodeObjectAt: &_contents_array[_count++] [aCoder decodeArrayOfObjCType: @encode(id)
withName: NULL]; count: count
at: _contents_array];
_count = count;
} }
return self; return self;
} }

View file

@ -29,7 +29,6 @@
#include <Foundation/NSUtilities.h> #include <Foundation/NSUtilities.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSPortCoder.h> #include <Foundation/NSPortCoder.h>
#include <gnustep/base/Coding.h>
#define FAST_MAP_RETAIN_VAL(X) X #define FAST_MAP_RETAIN_VAL(X) X
@ -106,31 +105,18 @@
{ {
unsigned count = map.nodeCount; unsigned count = map.nodeCount;
FastMapNode node = map.firstNode; FastMapNode node = map.firstNode;
SEL sel1 = @selector(encodeObject:);
IMP imp1 = [aCoder methodForSelector: sel1];
SEL sel2 = @selector(encodeValueOfObjCType:at:);
IMP imp2 = [aCoder methodForSelector: sel2];
const char *type = @encode(unsigned);
[(id<Encoding>)aCoder encodeValueOfCType: @encode(unsigned) (*imp2)(aCoder, sel2, type, &count);
at: &count
withName: @"Set content count"];
if ([aCoder isKindOfClass: [NSPortCoder class]] && while (node != 0) {
[(NSPortCoder*)aCoder isBycopy]) { (*imp1)(aCoder, sel1, node->key.o);
while (node != 0) { (*imp2)(aCoder, sel2, type, &node->value.I);
[(id<Encoding>)aCoder encodeBycopyObject: node->key.o node = node->nextInMap;
withName: @"Set value"];
[(id<Encoding>)aCoder encodeValueOfCType: @encode(unsigned)
at: &node->value.I
withName: @"Set value count"];
node = node->nextInMap;
}
}
else {
while (node != 0) {
[(id<Encoding>)aCoder encodeObject: node->key.o
withName: @"Set content"];
[(id<Encoding>)aCoder encodeValueOfCType: @encode(unsigned)
at: &node->value.I
withName: @"Set value count"];
node = node->nextInMap;
}
} }
} }
@ -139,17 +125,17 @@
unsigned count; unsigned count;
id value; id value;
unsigned valcnt; unsigned valcnt;
SEL sel = @selector(decodeValueOfObjCType:at:);
IMP imp = [aCoder methodForSelector: sel];
const char *utype = @encode(unsigned);
const char *otype = @encode(id);
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned) (*imp)(aCoder, sel, utype, &count);
at: &count
withName: NULL];
FastMapInitWithZoneAndCapacity(&map, [self zone], count); FastMapInitWithZoneAndCapacity(&map, [self zone], count);
while (count-- > 0) { while (count-- > 0) {
[(id<Decoding>)aCoder decodeObjectAt: &value withName: NULL]; (*imp)(aCoder, sel, otype, &value);
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned) (*imp)(aCoder, sel, utype, &valcnt);
at: &valcnt
withName: NULL];
FastMapAddPairNoRetain(&map, (FastMapItem)value, (FastMapItem)valcnt); FastMapAddPairNoRetain(&map, (FastMapItem)value, (FastMapItem)valcnt);
} }

View file

@ -29,7 +29,6 @@
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSPortCoder.h> #include <Foundation/NSPortCoder.h>
#include <gnustep/base/Coding.h>
#include <gnustep/base/fast.x> #include <gnustep/base/fast.x>
@ -151,29 +150,14 @@ myEqual(NSObject *self, NSObject *other)
{ {
unsigned count = map.nodeCount; unsigned count = map.nodeCount;
FastMapNode node = map.firstNode; FastMapNode node = map.firstNode;
SEL sel = @selector(encodeObject:);
IMP imp = [aCoder methodForSelector: sel];
[(id<Encoding>)aCoder encodeValueOfCType: @encode(unsigned) [aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
at: &count while (node != 0) {
withName: @"Dictionary content count"]; (*imp)(aCoder, sel, node->key.o);
(*imp)(aCoder, sel, node->value.o);
if ([aCoder isKindOfClass: [NSPortCoder class]] && node = node->nextInMap;
[(NSPortCoder*)aCoder isBycopy]) {
while (node != 0) {
[(id<Encoding>)aCoder encodeBycopyObject: node->key.o
withName: @"Dictionary key"];
[(id<Encoding>)aCoder encodeBycopyObject: node->value.o
withName: @"Dictionary content"];
node = node->nextInMap;
}
}
else {
while (node != 0) {
[(id<Encoding>)aCoder encodeObject: node->key.o
withName: @"Dictionary key"];
[(id<Encoding>)aCoder encodeObject: node->value.o
withName: @"Dictionary content"];
node = node->nextInMap;
}
} }
} }
@ -182,18 +166,19 @@ myEqual(NSObject *self, NSObject *other)
unsigned count; unsigned count;
id key; id key;
id value; id value;
SEL sel = @selector(decodeValueOfObjCType:at:);
IMP imp = [aCoder methodForSelector: sel];
const char *type = @encode(id);
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned) [aCoder decodeValueOfObjCType: @encode(unsigned)
at: &count at: &count];
withName: NULL];
FastMapInitWithZoneAndCapacity(&map, fastZone(self), count); FastMapInitWithZoneAndCapacity(&map, fastZone(self), count);
while (count-- > 0) { while (count-- > 0) {
[(id<Decoding>)aCoder decodeObjectAt: &key withName: NULL]; (*imp)(aCoder, sel, type, &key);
[(id<Decoding>)aCoder decodeObjectAt: &value withName: NULL]; (*imp)(aCoder, sel, type, &value);
FastMapAddPairNoRetain(&map, (FastMapItem)key, (FastMapItem)value); FastMapAddPairNoRetain(&map, (FastMapItem)key, (FastMapItem)value);
} }
return self; return self;
} }

View file

@ -30,7 +30,6 @@
#include <Foundation/NSUtilities.h> #include <Foundation/NSUtilities.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSPortCoder.h> #include <Foundation/NSPortCoder.h>
#include <gnustep/base/Coding.h>
#define FAST_MAP_HAS_VALUE 0 #define FAST_MAP_HAS_VALUE 0
@ -114,25 +113,13 @@
{ {
unsigned count = map.nodeCount; unsigned count = map.nodeCount;
FastMapNode node = map.firstNode; FastMapNode node = map.firstNode;
SEL sel = @selector(encodeObject:);
IMP imp = [aCoder methodForSelector: sel];
[(id<Encoding>)aCoder encodeValueOfCType: @encode(unsigned) [aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
at: &count while (node != 0) {
withName: @"Set content count"]; (*imp)(aCoder, sel, node->key.o);
node = node->nextInMap;
if ([aCoder isKindOfClass: [NSPortCoder class]] &&
[(NSPortCoder*)aCoder isBycopy]) {
while (node != 0) {
[(id<Encoding>)aCoder encodeBycopyObject: node->key.o
withName: @"Set content"];
node = node->nextInMap;
}
}
else {
while (node != 0) {
[(id<Encoding>)aCoder encodeObject: node->key.o
withName: @"Set content"];
node = node->nextInMap;
}
} }
} }
@ -140,14 +127,15 @@
{ {
unsigned count; unsigned count;
id value; id value;
SEL sel = @selector(decodeValueOfObjCType:at:);
IMP imp = [aCoder methodForSelector: sel];
const char *type = @encode(id);
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned) (*imp)(aCoder, sel, @encode(unsigned), &count);
at: &count
withName: NULL];
FastMapInitWithZoneAndCapacity(&map, [self zone], count); FastMapInitWithZoneAndCapacity(&map, [self zone], count);
while (count-- > 0) { while (count-- > 0) {
[(id<Decoding>)aCoder decodeObjectAt: &value withName: NULL]; (*imp)(aCoder, sel, type, &value);
FastMapAddKeyNoRetain(&map, (FastMapItem)value); FastMapAddKeyNoRetain(&map, (FastMapItem)value);
} }

View file

@ -44,6 +44,9 @@
fastCls _fastCls; /* Structure to cache classes. */ fastCls _fastCls; /* Structure to cache classes. */
fastImp _fastImp; /* Structure to cache methods. */ fastImp _fastImp; /* Structure to cache methods. */
@class NSDataMalloc;
@class NSMutableDataMalloc;
void _fastBuildCache() void _fastBuildCache()
{ {
/* /*
@ -56,6 +59,8 @@ void _fastBuildCache()
_fastCls._NSGCString = [NSGCString class]; _fastCls._NSGCString = [NSGCString class];
_fastCls._NSGMutableCString = [NSGMutableCString class]; _fastCls._NSGMutableCString = [NSGMutableCString class];
_fastCls._NXConstantString = [NXConstantString class]; _fastCls._NXConstantString = [NXConstantString class];
_fastCls._NSDataMalloc = [NSDataMalloc class];
_fastCls._NSMutableDataMalloc = [NSMutableDataMalloc class];
/* /*
* Cache some method implementations for quick access later. * Cache some method implementations for quick access later.

View file

@ -2011,6 +2011,13 @@ else
// xxx Sould we use NSScanner here ? // xxx Sould we use NSScanner here ?
- (BOOL) boolValue
{
if ([self caseInsensitiveCompare: @"YES"] == NSOrderedSame)
return YES;
return [self intValue] != 0 ? YES : NO;
}
- (double) doubleValue - (double) doubleValue
{ {
return atof([self cString]); return atof([self cString]);