more updates

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38803 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2015-07-16 08:44:15 +00:00
parent 46d97b3be0
commit 3b02814665
19 changed files with 138 additions and 119 deletions

View file

@ -1,3 +1,24 @@
2015-07-16 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/GNUstepBase/GSIMap.h:
* Headers/GNUstepBase/NSObject+GNUstepBase.h:
* Source/Additions/GSMime.m:
* Source/Additions/NSObject+GNUstepBase.m:
* Source/GSArray.m:
* Source/GSCountedSet.m:
* Source/GSDictionary.m:
* Source/GSPrivate.h:
* Source/GSSet.m:
* Source/GSString.m:
* Source/NSArray.m:
* Source/NSData.m:
* Source/NSDictionary.m:
* Source/NSObject.m:
* Source/NSSet.m:
* Source/NSString.m:
Rewriting naive implementations to improve efficiency and fix a few
bugs as well as renaming to avoid conflict with old GSCache.
2015-07-16 Niels Grewe <niels.grewe@halbordnung.de>
* Headers/GNUstepBase/NSHashTable+GNUstepBase.h

View file

@ -375,6 +375,7 @@ struct _GSIMapTable {
GSI_MAP_EXTRA extra;
#endif
};
#define GSI_MAP_TABLE_T GSIMapTable_t
#endif
typedef struct _GSIMapEnumerator {
@ -1268,7 +1269,7 @@ GSIMapSize(GSIMapTable map)
/* Map table plus arrays of pointers to chunks
*/
size = sizeof(*map) + map->chunkCount * sizeof(void*);
size = sizeof(GSI_MAP_TABLE_T) + map->chunkCount * sizeof(void*);
/* Add the array of buckets.
*/

View file

@ -100,11 +100,25 @@ extern "C" {
/** This is an informal protocol ... classes may implement the method to
* report how much memory is used by the instance and any objects it acts
* as a container for. The method should return zero if calling the
* superclass version returns zero (ie the object is in the exclude table).
* as a container for.
*/
@interface NSObject(MemorySize)
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude;
@interface NSObject(MemoryFootprint)
/* This method returns the memory usage of the receiver, excluding any
* objects already present in the exclude table.<br />
* The argument is a hash table configured to hold non-retained pointer
* objects and is used to inform the receiver that its size should not
* be counted again if it's already in the table.<br />
* The NSObject implementation returns zero if the receiver is in the
* table, but otherwise adds itself to the table and returns its memory
* footprint (the sum of all of its instance variables, but not any
* memory pointed to by those variables).<br />
* Subclasses should override this method by calling the superclass
* implementation, and either return the result (if it was zero) or
* return that value plus the sizes of any memory owned by the receiver
* (eg found by calling the same method on objects pointed to by the
* receiver's instance variables).
*/
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude;
@end
/** This is an informal protocol ... classes may implement the method and

View file

@ -4086,16 +4086,16 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
return value;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = [super sizeInBytes: exclude];
NSUInteger size = [super sizeInBytesExcluding: exclude];
if (size > 0)
{
size += [name sizeInBytes: exclude];
size += [value sizeInBytes: exclude];
size += [objects sizeInBytes: exclude];
size += [params sizeInBytes: exclude];
size += [name sizeInBytesExcluding: exclude];
size += [value sizeInBytesExcluding: exclude];
size += [objects sizeInBytesExcluding: exclude];
size += [params sizeInBytesExcluding: exclude];
}
return size;
}
@ -5803,7 +5803,7 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
*/
- (NSMutableData*) rawMimeData: (BOOL)isOuter
{
// 78 is the maximum line lengt specified by MIME RFCs
// 78 is the maximum line length specified by MIME RFCs
return [self rawMimeData: isOuter foldedAt: 78];
}
@ -6503,14 +6503,14 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
return hdr;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = [super sizeInBytes: exclude];
NSUInteger size = [super sizeInBytesExcluding: exclude];
if (size > 0)
{
size += [headers sizeInBytes: exclude];
size += [content sizeInBytes: exclude];
size += [headers sizeInBytesExcluding: exclude];
size += [content sizeInBytesExcluding: exclude];
}
return size;
}

View file

@ -305,12 +305,12 @@ GSPrivateMemorySize(NSObject *self, NSHashTable *exclude)
return 0;
}
@interface NSObject (MemorySize)
+ (NSUInteger) sizeInBytes: (NSHashTable*)exclude
@interface NSObject (MemoryFootprint)
+ (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
return 0;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
if (0 == NSHashGet(exclude, self))
{

View file

@ -132,7 +132,7 @@ NSCalendarDate+GNUstepBase.h \
NSData+GNUstepBase.h \
NSDebug+GNUstepBase.h \
NSFileHandle+GNUstepBase.h \
NSHashTable+GNUstepBase.h
NSHashTable+GNUstepBase.h \
NSLock+GNUstepBase.h \
NSMutableString+GNUstepBase.h \
NSNetServices+GNUstepBase.h \

View file

@ -972,7 +972,7 @@ static Class GSInlineArrayClass;
return count;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = GSPrivateMemorySize(self, exclude);
@ -983,7 +983,7 @@ static Class GSInlineArrayClass;
size += _capacity*sizeof(void*);
while (count-- > 0)
{
size += [[self objectAtIndex: count] sizeInBytes: exclude];
size += [_contents_array[count] sizeInBytesExcluding: exclude];
}
}
return size;

View file

@ -29,6 +29,7 @@
#import "Foundation/NSException.h"
#import "Foundation/NSPortCoder.h"
#import "GSPrivate.h"
#define GSI_MAP_RETAIN_VAL(M, X)
#define GSI_MAP_RELEASE_VAL(M, X)
@ -400,21 +401,16 @@ static GC_descr nodeDesc; // Type descriptor for map node.
if (size > 0)
{
NSUInteger count = [self count];
GSIMapEnumerator_t enumerator = GSIMapEnumeratorForMap(&map);
GSIMapNode node = GSIMapEnumeratorNextNode(&enumerator);
size += GSIMapSize(&map) - sizeof(map);
if (count > 0)
while (node != 0)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSEnumerator *enumerator = [self objectEnumerator];
NSObject *o;
while ((o = [enumerator nextObject]) != nil)
{
size += [o sizeInBytes: exclude];
}
[pool release];
}
node = GSIMapEnumeratorNextNode(&enumerator);
size += [node->key.obj sizeInBytes: exclude];
}
GSIMapEndEnumerator(&enumerator);
}
return size;
}

View file

@ -34,6 +34,8 @@
#import "GNUstepBase/GSObjCRuntime.h"
#import "GSPrivate.h"
/*
* The 'Fastmap' stuff provides an inline implementation of a mapping
* table - for maximum performance.
@ -365,29 +367,23 @@ static SEL objSel;
(&map, state, stackbuf, len);
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = GSPrivateMemorySize(self, exclude);
if (size > 0)
{
NSUInteger count = [self count];
GSIMapEnumerator_t enumerator = GSIMapEnumeratorForMap(&map);
GSIMapNode node = GSIMapEnumeratorNextNode(&enumerator);
size += GSIMapSize(&map) - sizeof(map);
if (count > 0)
while (node != 0)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSEnumerator *enumerator = [self keyEnumerator];
NSObject *k;
while ((k = [enumerator nextObject]) != nil)
{
NSObject *o = [self objectForKey: k];
size += [k sizeInBytes: exclude] + [o sizeInBytes: exclude];
}
[pool release];
}
node = GSIMapEnumeratorNextNode(&enumerator);
size += [node->key.obj sizeInBytesExcluding: exclude];
size += [node->value.obj sizeInBytesExcluding: exclude];
}
GSIMapEndEnumerator(&enumerator);
}
return size;
}

View file

@ -544,21 +544,16 @@ static Class mutableSetClass;
if (size > 0)
{
NSUInteger count = [self count];
GSIMapEnumerator_t enumerator = GSIMapEnumeratorForMap(&map);
GSIMapNode node = GSIMapEnumeratorNextNode(&enumerator);
size += GSIMapSize(&map) - sizeof(map);
if (count > 0)
while (node != 0)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSEnumerator *enumerator = [self objectEnumerator];
NSObject *o;
while ((o = [enumerator nextObject]) != nil)
{
size += [o sizeInBytes: exclude];
}
[pool release];
}
node = GSIMapEnumeratorNextNode(&enumerator);
size += [node->key.obj sizeInBytes: exclude];
}
GSIMapEndEnumerator(&enumerator);
}
return size;
}

View file

@ -1088,7 +1088,7 @@ tsbytes(uintptr_t s, char *buf)
return;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
if (0 == NSHashGet(exclude, self))
{
@ -3844,7 +3844,7 @@ transmute(GSStr self, NSString *aString)
freeWhenDone: flag];
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = GSPrivateMemorySize(self, exclude);
@ -5665,7 +5665,7 @@ NSAssert(_flags.owned == 1 && _zone != 0, NSInternalInconsistencyException);
return _count;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = GSPrivateMemorySize(self, exclude);

View file

@ -1964,9 +1964,9 @@ compare(id elem1, id elem2, void* context)
passingTest: predicate];
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = [super sizeInBytes: exclude];
NSUInteger size = [super sizeInBytesExcluding: exclude];
if (size > 0)
{
@ -1975,7 +1975,7 @@ compare(id elem1, id elem2, void* context)
size += count*sizeof(void*);
while (count-- > 0)
{
size += [[self objectAtIndex: count] sizeInBytes: exclude];
size += [[self objectAtIndex: count] sizeInBytesExcluding: exclude];
}
}
return size;

View file

@ -1066,27 +1066,25 @@ const NSHashTableCallBacks NSPointerToStructHashCallBacks =
}
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = [super sizeInBytes: exclude];
NSUInteger size = [super sizeInBytesExcluding: exclude];
if (size > 0)
{
NSUInteger count = [self count];
size += GSIMapSize(self);
if (count > 0)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSEnumerator *enumerator = [self objectEnumerator];
NSObject *o;
while ((o = [enumerator nextObject]) != nil)
{
size += [o sizeInBytes: exclude];
}
[pool release];
}
/* If we knew that this table held objects, we could return their size...
*
* GSIMapEnumerator_t enumerator = GSIMapEnumeratorForMap(self);
* GSIMapNode node = GSIMapEnumeratorNextNode(&enumerator);
*
* while (node != 0)
* {
* node = GSIMapEnumeratorNextNode(&enumerator);
* size += [node->key.obj sizeInBytesExcluding: exclude];
* }
* GSIMapEndEnumerator(&enumerator);
*/
size += GSIMapSize(self) - sizeof(GSI_MAP_TABLE_T);
}
return size;
}

View file

@ -1431,29 +1431,26 @@ const NSMapTableValueCallBacks NSOwnedPointerMapValueCallBacks =
return [p autorelease];
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = [super sizeInBytes: exclude];
NSUInteger size = [super sizeInBytesExcluding: exclude];
if (size > 0)
{
NSUInteger count = [self count];
size += GSIMapSize(self);
if (count > 0)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSEnumerator *enumerator = [self keyEnumerator];
NSObject *k;
while ((k = [enumerator nextObject]) != nil)
{
NSObject *o = [self objectForKey: k];
size += [k sizeInBytes: exclude] + [o sizeInBytes: exclude];
}
[pool release];
}
/* If we knew that this table held objects, we could return their size...
*
* GSIMapEnumerator_t enumerator = GSIMapEnumeratorForMap(self);
* GSIMapNode node = GSIMapEnumeratorNextNode(&enumerator);
*
* while (node != 0)
* {
* node = GSIMapEnumeratorNextNode(&enumerator);
* size += [node->key.obj sizeInBytesExcluding: exclude];
* size += [node->value.obj sizeInBytesExcluding: exclude];
* }
* GSIMapEndEnumerator(&enumerator);
*/
size += GSIMapSize(self) - sizeof(GSI_MAP_TABLE_T);
}
return size;
}

View file

@ -1981,9 +1981,9 @@ failure:
return NO;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = [super sizeInBytes: exclude];
NSUInteger size = [super sizeInBytesExcluding: exclude];
if (size > 0)
{
@ -3294,7 +3294,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
}
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = GSPrivateMemorySize(self, exclude);
@ -3358,7 +3358,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
return self;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = GSPrivateMemorySize(self, exclude);
@ -4192,7 +4192,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
length = size;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = GSPrivateMemorySize(self, exclude);

View file

@ -1230,9 +1230,9 @@ compareIt(id o1, id o2, void* context)
return 0;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = [super sizeInBytes: exclude];
NSUInteger size = [super sizeInBytesExcluding: exclude];
if (size > 0)
{
@ -1249,7 +1249,8 @@ compareIt(id o1, id o2, void* context)
{
NSObject *o = [self objectForKey: k];
size += [k sizeInBytes: exclude] + [o sizeInBytes: exclude];
size += [k sizeInBytesExcluding: exclude];
size += [o sizeInBytesExcluding: exclude];
}
[pool release];
}

View file

@ -2619,12 +2619,12 @@ GSPrivateMemorySize(NSObject *self, NSHashTable *exclude)
return 0;
}
@implementation NSObject (MemorySize)
+ (NSUInteger) sizeInBytes: (NSHashTable*)exclude
@implementation NSObject (MemoryFootprint)
+ (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
return 0;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
return GSPrivateMemorySize(self, exclude);
}

View file

@ -999,9 +999,9 @@ static Class NSMutableSet_concrete_class;
return 0;
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = [super sizeInBytes: exclude];
NSUInteger size = [super sizeInBytesExcluding: exclude];
if (size > 0)
{
@ -1016,7 +1016,7 @@ static Class NSMutableSet_concrete_class;
while ((o = [enumerator nextObject]) != nil)
{
size += [o sizeInBytes: exclude];
size += [o sizeInBytesExcluding: exclude];
}
[pool release];
}

View file

@ -5923,9 +5923,9 @@ static NSFileManager *fm = nil;
return GSPropertyListFromStringsFormat(self);
}
- (NSUInteger) sizeInBytes: (NSHashTable*)exclude
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = [super sizeInBytes: exclude];
NSUInteger size = [super sizeInBytesExcluding: exclude];
if (size > 0)
{