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 Frith-MacDonald 1999-06-09 16:12:20 +00:00
parent c531b49651
commit 27118f1f54
2 changed files with 17 additions and 22 deletions

View file

@ -91,16 +91,16 @@
* The default is NOT to deserialize uniqued strings.
*
* The [+uniquing:] method turns uniquing on/off. Turning off uniquing
* destroys the NSCountedSet used for uniquing.
* The [+purge] method lets you remove some of the objects from the
* NSCountedSet used for uniquing. The count of each string in the
* set is decreased, so that strings that have only been deserialized
* once are removed.
* destroys the NSMutableSet used for uniquing.
* The [+uniqueSet] method gives you direct access to the uniquing set.
* The [+unique:] method lets you find the 'uniqued' version os a string.
*/
@class NSMutableSet;
@interface NSDeserializer (GNUstep)
+ (void) _becomeThreaded: (id)notification; /* private */
+ (void) purge;
+ (NSString*) unique: (NSString*)original;
+ (void) uniquing: (BOOL)flag;
+ (NSMutableSet*) uniqueSet;
@end
#endif

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