mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
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:
parent
890486a0b8
commit
609f48e404
9 changed files with 814 additions and 600 deletions
|
@ -112,8 +112,16 @@
|
|||
* object - or they will find it's buffer disappearing unexpectedly.
|
||||
* Once you have used this method, you own the malloced data and are
|
||||
* 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*) relinquishAllocatedBytesFromZone: (NSZone*)aZone;
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -264,6 +264,7 @@ enum {
|
|||
#endif
|
||||
|
||||
#ifndef NO_GNUSTEP
|
||||
- (BOOL) boolValue;
|
||||
- (NSString*) descriptionForPropertyList;
|
||||
- (id) initWithCharactersNoCopy: (unichar*)chars
|
||||
length: (unsigned int)length
|
||||
|
|
1210
Source/NSData.m
1210
Source/NSData.m
File diff suppressed because it is too large
Load diff
|
@ -28,7 +28,6 @@
|
|||
#include <gnustep/base/behavior.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSPortCoder.h>
|
||||
#include <gnustep/base/Coding.h>
|
||||
|
||||
@interface NSGArray : NSArray
|
||||
{
|
||||
|
@ -105,46 +104,28 @@
|
|||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
[(id<Encoding>)aCoder encodeValueOfCType: @encode(unsigned)
|
||||
at: &_count
|
||||
withName: @"Array content count"];
|
||||
|
||||
for (i = 0; i < _count; i++) {
|
||||
[(id<Encoding>)aCoder encodeObject: _contents_array[i]
|
||||
withName: @"Array content"];
|
||||
[aCoder encodeValueOfObjCType: @encode(unsigned)
|
||||
at: &_count];
|
||||
if (_count > 0) {
|
||||
[aCoder encodeArrayOfObjCType: @encode(id)
|
||||
count: _count
|
||||
at: _contents_array];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
unsigned count;
|
||||
|
||||
#if 0
|
||||
unsigned dummy;
|
||||
|
||||
[(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);
|
||||
[aCoder decodeValueOfObjCType: @encode(unsigned)
|
||||
at: &_count];
|
||||
if (_count > 0) {
|
||||
_contents_array = NSZoneCalloc([self zone], _count, sizeof(id));
|
||||
if (_contents_array == 0) {
|
||||
[NSException raise: NSMallocException
|
||||
format: @"Unable to make array"];
|
||||
}
|
||||
while (_count < count) {
|
||||
[(id<Decoding>)aCoder decodeObjectAt: &_contents_array[_count++]
|
||||
withName: NULL];
|
||||
}
|
||||
[aCoder decodeArrayOfObjCType: @encode(id)
|
||||
count: _count
|
||||
at: _contents_array];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -245,16 +226,17 @@
|
|||
{
|
||||
unsigned count;
|
||||
|
||||
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
|
||||
at: &count
|
||||
withName: NULL];
|
||||
[aCoder decodeValueOfObjCType: @encode(unsigned)
|
||||
at: &count];
|
||||
if ([self initWithCapacity: count] == nil) {
|
||||
[NSException raise: NSMallocException
|
||||
format: @"Unable to make array"];
|
||||
}
|
||||
while (_count < count) {
|
||||
[(id<Decoding>)aCoder decodeObjectAt: &_contents_array[_count++]
|
||||
withName: NULL];
|
||||
if (count > 0) {
|
||||
[aCoder decodeArrayOfObjCType: @encode(id)
|
||||
count: count
|
||||
at: _contents_array];
|
||||
_count = count;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <Foundation/NSUtilities.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSPortCoder.h>
|
||||
#include <gnustep/base/Coding.h>
|
||||
|
||||
|
||||
#define FAST_MAP_RETAIN_VAL(X) X
|
||||
|
@ -106,31 +105,18 @@
|
|||
{
|
||||
unsigned count = map.nodeCount;
|
||||
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)
|
||||
at: &count
|
||||
withName: @"Set content count"];
|
||||
(*imp2)(aCoder, sel2, type, &count);
|
||||
|
||||
if ([aCoder isKindOfClass: [NSPortCoder class]] &&
|
||||
[(NSPortCoder*)aCoder isBycopy]) {
|
||||
while (node != 0) {
|
||||
[(id<Encoding>)aCoder encodeBycopyObject: node->key.o
|
||||
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;
|
||||
}
|
||||
while (node != 0) {
|
||||
(*imp1)(aCoder, sel1, node->key.o);
|
||||
(*imp2)(aCoder, sel2, type, &node->value.I);
|
||||
node = node->nextInMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,17 +125,17 @@
|
|||
unsigned count;
|
||||
id value;
|
||||
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)
|
||||
at: &count
|
||||
withName: NULL];
|
||||
(*imp)(aCoder, sel, utype, &count);
|
||||
|
||||
FastMapInitWithZoneAndCapacity(&map, [self zone], count);
|
||||
while (count-- > 0) {
|
||||
[(id<Decoding>)aCoder decodeObjectAt: &value withName: NULL];
|
||||
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
|
||||
at: &valcnt
|
||||
withName: NULL];
|
||||
(*imp)(aCoder, sel, otype, &value);
|
||||
(*imp)(aCoder, sel, utype, &valcnt);
|
||||
FastMapAddPairNoRetain(&map, (FastMapItem)value, (FastMapItem)valcnt);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSPortCoder.h>
|
||||
#include <gnustep/base/Coding.h>
|
||||
|
||||
#include <gnustep/base/fast.x>
|
||||
|
||||
|
@ -151,29 +150,14 @@ myEqual(NSObject *self, NSObject *other)
|
|||
{
|
||||
unsigned count = map.nodeCount;
|
||||
FastMapNode node = map.firstNode;
|
||||
SEL sel = @selector(encodeObject:);
|
||||
IMP imp = [aCoder methodForSelector: sel];
|
||||
|
||||
[(id<Encoding>)aCoder encodeValueOfCType: @encode(unsigned)
|
||||
at: &count
|
||||
withName: @"Dictionary content count"];
|
||||
|
||||
if ([aCoder isKindOfClass: [NSPortCoder class]] &&
|
||||
[(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;
|
||||
}
|
||||
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
|
||||
while (node != 0) {
|
||||
(*imp)(aCoder, sel, node->key.o);
|
||||
(*imp)(aCoder, sel, node->value.o);
|
||||
node = node->nextInMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,18 +166,19 @@ myEqual(NSObject *self, NSObject *other)
|
|||
unsigned count;
|
||||
id key;
|
||||
id value;
|
||||
SEL sel = @selector(decodeValueOfObjCType:at:);
|
||||
IMP imp = [aCoder methodForSelector: sel];
|
||||
const char *type = @encode(id);
|
||||
|
||||
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
|
||||
at: &count
|
||||
withName: NULL];
|
||||
[aCoder decodeValueOfObjCType: @encode(unsigned)
|
||||
at: &count];
|
||||
|
||||
FastMapInitWithZoneAndCapacity(&map, fastZone(self), count);
|
||||
while (count-- > 0) {
|
||||
[(id<Decoding>)aCoder decodeObjectAt: &key withName: NULL];
|
||||
[(id<Decoding>)aCoder decodeObjectAt: &value withName: NULL];
|
||||
(*imp)(aCoder, sel, type, &key);
|
||||
(*imp)(aCoder, sel, type, &value);
|
||||
FastMapAddPairNoRetain(&map, (FastMapItem)key, (FastMapItem)value);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include <Foundation/NSUtilities.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSPortCoder.h>
|
||||
#include <gnustep/base/Coding.h>
|
||||
|
||||
#define FAST_MAP_HAS_VALUE 0
|
||||
|
||||
|
@ -114,25 +113,13 @@
|
|||
{
|
||||
unsigned count = map.nodeCount;
|
||||
FastMapNode node = map.firstNode;
|
||||
SEL sel = @selector(encodeObject:);
|
||||
IMP imp = [aCoder methodForSelector: sel];
|
||||
|
||||
[(id<Encoding>)aCoder encodeValueOfCType: @encode(unsigned)
|
||||
at: &count
|
||||
withName: @"Set content count"];
|
||||
|
||||
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;
|
||||
}
|
||||
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
|
||||
while (node != 0) {
|
||||
(*imp)(aCoder, sel, node->key.o);
|
||||
node = node->nextInMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,14 +127,15 @@
|
|||
{
|
||||
unsigned count;
|
||||
id value;
|
||||
SEL sel = @selector(decodeValueOfObjCType:at:);
|
||||
IMP imp = [aCoder methodForSelector: sel];
|
||||
const char *type = @encode(id);
|
||||
|
||||
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
|
||||
at: &count
|
||||
withName: NULL];
|
||||
(*imp)(aCoder, sel, @encode(unsigned), &count);
|
||||
|
||||
FastMapInitWithZoneAndCapacity(&map, [self zone], count);
|
||||
while (count-- > 0) {
|
||||
[(id<Decoding>)aCoder decodeObjectAt: &value withName: NULL];
|
||||
(*imp)(aCoder, sel, type, &value);
|
||||
FastMapAddKeyNoRetain(&map, (FastMapItem)value);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
fastCls _fastCls; /* Structure to cache classes. */
|
||||
fastImp _fastImp; /* Structure to cache methods. */
|
||||
|
||||
@class NSDataMalloc;
|
||||
@class NSMutableDataMalloc;
|
||||
|
||||
void _fastBuildCache()
|
||||
{
|
||||
/*
|
||||
|
@ -56,6 +59,8 @@ void _fastBuildCache()
|
|||
_fastCls._NSGCString = [NSGCString class];
|
||||
_fastCls._NSGMutableCString = [NSGMutableCString class];
|
||||
_fastCls._NXConstantString = [NXConstantString class];
|
||||
_fastCls._NSDataMalloc = [NSDataMalloc class];
|
||||
_fastCls._NSMutableDataMalloc = [NSMutableDataMalloc class];
|
||||
|
||||
/*
|
||||
* Cache some method implementations for quick access later.
|
||||
|
|
|
@ -2011,6 +2011,13 @@ else
|
|||
|
||||
// xxx Sould we use NSScanner here ?
|
||||
|
||||
- (BOOL) boolValue
|
||||
{
|
||||
if ([self caseInsensitiveCompare: @"YES"] == NSOrderedSame)
|
||||
return YES;
|
||||
return [self intValue] != 0 ? YES : NO;
|
||||
}
|
||||
|
||||
- (double) doubleValue
|
||||
{
|
||||
return atof([self cString]);
|
||||
|
|
Loading…
Reference in a new issue