diff --git a/ChangeLog b/ChangeLog index b14fabdc1..d46e517f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2001-05-22 Richard Frith-Macdonald + * Headers/Foundation/NSSet.h: Added ([-setSet:]) + * Source/GSSet.m: Optimise ([-unionSet:]) + * Source/GSArray.m: Tidy NSWarnMLog macros. + * Source/GSAttributedString.m: ditto + * Source/GSCountedSet.m: ditto + * Source/GSDictionary.m: ditto + * Source/NSArray.m: ditto + * Source/NSDictionary.m: ditto + * Source/NSSet.m: Implement ([-setSet:]) + 2001-05-18 Richard Frith-Macdonald * Source/NSDate.m: check for nil dates in some init methods so diff --git a/Headers/gnustep/base/NSSet.h b/Headers/gnustep/base/NSSet.h index 5a90c9725..3f80ae41e 100644 --- a/Headers/gnustep/base/NSSet.h +++ b/Headers/gnustep/base/NSSet.h @@ -73,8 +73,10 @@ - (void) minusSet: (NSSet*)other; - (void) removeAllObjects; - (void) removeObject: (id)anObject; +#ifndef STRICT_OPENSTEP +- (void) setSet: (NSSet*)other; +#endif - (void) unionSet: (NSSet*)other; - @end @interface NSCountedSet : NSMutableSet diff --git a/Source/GSArray.m b/Source/GSArray.m index 3887c3f44..8b5874bf2 100644 --- a/Source/GSArray.m +++ b/Source/GSArray.m @@ -470,7 +470,7 @@ static SEL eqSel; if (anObject == nil) { - NSWarnMLog(@"attempt to remove nil object", 0); + NSWarnMLog(@"attempt to remove nil object"); return; } index = _count; @@ -540,7 +540,7 @@ static SEL eqSel; if (anObject == nil) { - NSWarnMLog(@"attempt to remove nil object", 0); + NSWarnMLog(@"attempt to remove nil object"); return; } index = _count; @@ -653,7 +653,7 @@ static SEL eqSel; #ifdef GSWARN if (badComparison == YES) { - NSWarnMLog(@"Detected bad return value from comparison", 0); + NSWarnMLog(@"Detected bad return value from comparison"); } #endif } diff --git a/Source/GSAttributedString.m b/Source/GSAttributedString.m index ce926365f..91a9026ab 100644 --- a/Source/GSAttributedString.m +++ b/Source/GSAttributedString.m @@ -610,7 +610,7 @@ SANITY(); if (range.length == 0) { - NSWarnMLog(@"Attempt to set attribute for zero-length range", 0); + NSWarnMLog(@"Attempt to set attribute for zero-length range"); return; } if (attributes == nil) diff --git a/Source/GSCountedSet.m b/Source/GSCountedSet.m index ef19c69e3..0ec47c5e7 100644 --- a/Source/GSCountedSet.m +++ b/Source/GSCountedSet.m @@ -284,7 +284,7 @@ if (anObject == nil) { - NSWarnMLog(@"attempt to remove nil object", 0); + NSWarnMLog(@"attempt to remove nil object"); return; } bucket = GSIMapBucketForKey(&map, (GSIMapKey)anObject); diff --git a/Source/GSSet.m b/Source/GSSet.m index 7bc06314f..984c9da95 100644 --- a/Source/GSSet.m +++ b/Source/GSSet.m @@ -566,7 +566,7 @@ static Class mutableSetClass; { if (anObject == nil) { - NSWarnMLog(@"attempt to remove nil object", 0); + NSWarnMLog(@"attempt to remove nil object"); return; } GSIMapRemoveKey(&map, (GSIMapKey)anObject); @@ -577,21 +577,27 @@ static Class mutableSetClass; if (other != self) { NSEnumerator *e = [other objectEnumerator]; - id anObject; - while ((anObject = [e nextObject]) != nil) + if (e != nil) { - GSIMapNode node; + id anObject; + SEL sel = @selector(nextObject); + IMP imp = [e methodForSelector: sel]; - if (anObject == nil) + while ((anObject = (*imp)(e, sel)) != nil) { - [NSException raise: NSInvalidArgumentException - format: @"Tried to add nil to set"]; - } - node = GSIMapNodeForKey(&map, (GSIMapKey)anObject); - if (node == 0) - { - GSIMapAddKey(&map, (GSIMapKey)anObject); + GSIMapNode node; + + if (anObject == nil) + { + [NSException raise: NSInvalidArgumentException + format: @"Tried to add nil to set"]; + } + node = GSIMapNodeForKey(&map, (GSIMapKey)anObject); + if (node == 0) + { + GSIMapAddKey(&map, (GSIMapKey)anObject); + } } } } diff --git a/Source/NSArray.m b/Source/NSArray.m index 23179e463..0c497e28f 100644 --- a/Source/NSArray.m +++ b/Source/NSArray.m @@ -993,7 +993,7 @@ static NSString *indentStrings[] = { if (anObject == nil) { - NSWarnMLog(@"attempt to remove nil object", 0); + NSWarnMLog(@"attempt to remove nil object"); return; } i = [self count]; @@ -1026,7 +1026,7 @@ static NSString *indentStrings[] = { if (anObject == nil) { - NSWarnMLog(@"attempt to remove nil object", 0); + NSWarnMLog(@"attempt to remove nil object"); return; } c = [self count]; @@ -1079,7 +1079,7 @@ static NSString *indentStrings[] = { if (anObject == nil) { - NSWarnMLog(@"attempt to remove nil object", 0); + NSWarnMLog(@"attempt to remove nil object"); return; } c = [self count]; @@ -1116,7 +1116,7 @@ static NSString *indentStrings[] = { if (anObject == nil) { - NSWarnMLog(@"attempt to remove nil object", 0); + NSWarnMLog(@"attempt to remove nil object"); return; } i = [self count]; @@ -1362,7 +1362,7 @@ static NSString *indentStrings[] = { #ifdef GSWARN if (badComparison == YES) { - NSWarnMLog(@"Detected bad return value from comparison", 0); + NSWarnMLog(@"Detected bad return value from comparison"); } #endif } diff --git a/Source/NSDictionary.m b/Source/NSDictionary.m index 036cdeded..4fe45185f 100644 --- a/Source/NSDictionary.m +++ b/Source/NSDictionary.m @@ -861,7 +861,7 @@ static NSString *indentStrings[] = { #ifdef GSWARN if (badComparison == YES) { - NSWarnMLog(@"Detected bad return value from comparison", 0); + NSWarnMLog(@"Detected bad return value from comparison"); } #endif } diff --git a/Source/NSSet.m b/Source/NSSet.m index a618f685e..1a913cfe7 100644 --- a/Source/NSSet.m +++ b/Source/NSSet.m @@ -30,6 +30,7 @@ #include #include #include +#include @class GSSet; @class GSMutableSet; @@ -523,20 +524,6 @@ static Class NSMutableSet_concrete_class; } } -- (void) unionSet: (NSSet*) other -{ - if (other != self) - { - id keys = [other objectEnumerator]; - id key; - - while ((key = [keys nextObject])) - { - [self addObject: key]; - } - } -} - - (void) intersectSet: (NSSet*) other { if (other != self) @@ -577,4 +564,38 @@ static Class NSMutableSet_concrete_class; [self subclassResponsibility: _cmd]; } +- (void) setSet: (NSSet*)other +{ + if (other == self) + { + return; + } + if (other == nil) + { + NSWarnMLog(@"Setting mutable set to nil"); + [self removeAllObjects]; + } + else + { + RETAIN(other); // In case it's held by us + [self removeAllObjects]; + [self unionSet: other]; + RELEASE(other); + } +} + +- (void) unionSet: (NSSet*) other +{ + if (other != self) + { + id keys = [other objectEnumerator]; + id key; + + while ((key = [keys nextObject])) + { + [self addObject: key]; + } + } +} + @end