Index: src/OFCountedSet.m ================================================================== --- src/OFCountedSet.m +++ src/OFCountedSet.m @@ -262,9 +262,24 @@ [self addObject: object]; } } else for (id object in set) [self addObject: object]; + + objc_autoreleasePoolPop(pool); +} + +- (void)removeAllObjects +{ + void *pool = objc_autoreleasePoolPush(); + OFSet *copy = [[self copy] autorelease]; + + for (id object in copy) { + size_t count = [self countForObject: object]; + + for (size_t i = 0; i < count; i++) + [self removeObject: object]; + } objc_autoreleasePoolPop(pool); } @end Index: src/OFCountedSet_hashtable.m ================================================================== --- src/OFCountedSet_hashtable.m +++ src/OFCountedSet_hashtable.m @@ -208,10 +208,15 @@ [_mapTable setObject: (void *)(uintptr_t)count forKey: object]; else [_mapTable removeObjectForKey: object]; } + +- (void)removeAllObjects +{ + [_mapTable removeAllObjects]; +} - (void)makeImmutable { } @end Index: src/OFMutableSet.h ================================================================== --- src/OFMutableSet.h +++ src/OFMutableSet.h @@ -79,10 +79,15 @@ * * @param set The set to create the union with */ - (void)unionSet: (OFSet OF_GENERIC(ObjectType) *)set; +/*! + * @brief Removes all objects from the set. + */ +- (void)removeAllObjects; + /*! * @brief Converts the mutable set to an immutable set. */ - (void)makeImmutable; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -191,10 +191,21 @@ - (void)unionSet: (OFSet *)set { for (id object in set) [self addObject: object]; } + +- (void)removeAllObjects +{ + void *pool = objc_autoreleasePoolPush(); + OFSet *copy = [[self copy] autorelease]; + + for (id object in copy) + [self removeObject: object]; + + objc_autoreleasePoolPop(pool); +} - (void)makeImmutable { } @end Index: src/OFMutableSet_hashtable.m ================================================================== --- src/OFMutableSet_hashtable.m +++ src/OFMutableSet_hashtable.m @@ -35,11 +35,16 @@ - (void)removeObject: (id)object { [_mapTable removeObjectForKey: object]; } + +- (void)removeAllObjects +{ + [_mapTable removeAllObjects]; +} - (void)makeImmutable { object_setClass(self, [OFSet_hashtable class]); } @end Index: tests/OFSetTests.m ================================================================== --- tests/OFSetTests.m +++ tests/OFSetTests.m @@ -88,10 +88,14 @@ TEST(@"-[unionSet:]", R([mutableSet unionSet: [OFSet setWithObjects: @"x", @"bar", nil]]) && [mutableSet isEqual: [OFSet setWithObjects: @"baz", @"bar", @"x", nil]]) + TEST(@"-[removeAllObjects]", + R([mutableSet removeAllObjects]) && + [mutableSet isEqual: [OFSet set]]) + ok = true; i = 0; for (OFString *s in set1) { switch (i) { @@ -120,10 +124,12 @@ ok = false; TEST(@"Fast enumeration", ok) ok = false; + [mutableSet addObject: @"foo"]; + [mutableSet addObject: @"bar"]; @try { for (OFString *s in mutableSet) [mutableSet removeObject: s]; } @catch (OFEnumerationMutationException *e) { ok = true;