Optimise dictionary content sort when creating description

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4880 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-09-12 20:30:42 +00:00
parent 85835779a2
commit 1a3f09f836

View file

@ -24,6 +24,7 @@
#include <config.h> #include <config.h>
#include <base/behavior.h> #include <base/behavior.h>
#include <base/fast.x>
#include <Foundation/NSDictionary.h> #include <Foundation/NSDictionary.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSUtilities.h> #include <Foundation/NSUtilities.h>
@ -656,6 +657,7 @@ static NSString *indentStrings[] = {
NSString *plists[numKeys]; NSString *plists[numKeys];
NSString *keys[numKeys]; NSString *keys[numKeys];
IMP appImp; IMP appImp;
Class lastClass = 0;
appImp = [(NSObject*)result methodForSelector: appSel]; appImp = [(NSObject*)result methodForSelector: appSel];
@ -672,11 +674,14 @@ static NSString *indentStrings[] = {
[keyArray getObjects: keys]; [keyArray getObjects: keys];
for (i = 0; i < numKeys; i++) for (i = 0; i < numKeys; i++)
{ {
if (fastClass(keys[i]) == lastClass)
continue;
if ([keys[i] respondsToSelector: @selector(compare:)] == NO) if ([keys[i] respondsToSelector: @selector(compare:)] == NO)
{ {
canCompare = NO; canCompare = NO;
break; break;
} }
lastClass = fastClass(keys[i]);
} }
if (canCompare) if (canCompare)
@ -689,12 +694,13 @@ static NSString *indentStrings[] = {
#define STRIDE_FACTOR 3 #define STRIDE_FACTOR 3
unsigned c,d, stride; unsigned c,d, stride;
BOOL found; BOOL found;
NSComparisonResult (*comp)(id, SEL, id);
int count = numKeys; int count = numKeys;
stride = 1; stride = 1;
while (stride <= count) while (stride <= count)
stride = stride * STRIDE_FACTOR + 1; stride = stride * STRIDE_FACTOR + 1;
lastClass = 0;
while(stride > (STRIDE_FACTOR - 1)) while(stride > (STRIDE_FACTOR - 1))
{ {
// loop to sort for each value of stride // loop to sort for each value of stride
@ -710,7 +716,16 @@ static NSString *indentStrings[] = {
// move to left until correct place // move to left until correct place
id a = keys[d + stride]; id a = keys[d + stride];
id b = keys[d]; id b = keys[d];
if ([a compare: b] == NSOrderedAscending) Class x;
x = fastClass(a);
if (x != lastClass)
{
lastClass = x;
comp = (NSComparisonResult (*)(id, SEL, id))
[a methodForSelector: @selector(compare:)];
}
if ((*comp)(a, @selector(compare:), b) == NSOrderedAscending)
{ {
keys[d + stride] = b; keys[d + stride] = b;
keys[d] = a; keys[d] = a;