Tidied uniquing

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4384 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-06-09 16:12:20 +00:00
parent f262658edc
commit b12df995c0
2 changed files with 17 additions and 22 deletions

View file

@ -351,7 +351,7 @@ static BOOL shouldBeCompact = NO;
* Class variables for uniquing incoming strings.
*/
static NSRecursiveLock *uniqueLock = nil;
static NSCountedSet *uniqueSet = nil;
static NSMutableSet *uniqueSet = nil;
/*
* Variables to cache class information.
@ -774,28 +774,23 @@ deserializeFromInfo(_NSDeserializerInfo* info)
uniqueLock = [NSRecursiveLock new];
}
/*
* Remove one copy of each object in the uniquing set, or remove all
* objects if the flag is YES.
*/
+ (void) purge
+ (NSMutableSet*) uniqueSet
{
return uniqueSet;
}
+ (NSString*) unique: (NSString*)str
{
if (uniqueSet)
{
NSArray *all;
id obj;
unsigned i;
if (uniqueLock != nil)
[uniqueLock lock];
all = [uniqueSet allObjects];
for (i = [all count]; i > 0; i--)
{
[uniqueSet removeObject: [all objectAtIndex: i-1]];
}
[uniqueSet addObject: str];
str = [uniqueSet member: str];
if (uniqueLock != nil)
[uniqueLock unlock];
}
return str;
}
/*
@ -809,7 +804,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
{
if (uniqueSet == nil)
{
uniqueSet = [NSCountedSet new];
uniqueSet = [NSMutableSet new];
}
}
else