Index: src/OFDataArray.h ================================================================== --- src/OFDataArray.h +++ src/OFDataArray.h @@ -237,10 +237,15 @@ /** * \brief Removes the last item. */ - (void)removeLastItem; +/** + * \brief Removes all items. + */ +- (void)removeAllItems; + /** * \brief Returns a string containing the data in Base64 encoding. * * \return A string containing the data in Base64 encoding */ Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -358,10 +358,18 @@ ofSize: itemSize]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } + +- (void)removeAllItems +{ + [self freeMemory: data]; + + data = NULL; + count = 0; +} - copy { OFDataArray *copy = [[isa alloc] initWithItemSize: itemSize]; @@ -602,6 +610,15 @@ } size = newSize; } } + +- (void)removeAllItems +{ + [self freeMemory: data]; + + data = NULL; + count = 0; + size = 0; +} @end Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -109,10 +109,15 @@ /** * \brief Removes the last object. */ - (void)removeLastObject; +/** + * \brief Removes all objects. + */ +- (void)removeAllObjects; + #ifdef OF_HAVE_BLOCKS /** * \brief Replaces each object with the object returned by the block. * * \param block The block which returns a new object for each object Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -278,10 +278,15 @@ - (void)removeLastObject { [self removeNObjects: 1]; } + +- (void)removeAllObjects +{ + [self removeNObjects: [self count]]; +} #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block { [self enumerateObjectsUsingBlock: ^ (id object, size_t index, Index: src/OFMutableArray_adjacent.m ================================================================== --- src/OFMutableArray_adjacent.m +++ src/OFMutableArray_adjacent.m @@ -165,10 +165,21 @@ [copy[i] release]; } @finally { [self freeMemory: copy]; } } + +- (void)removeAllObjects +{ + id *cArray = [array cArray]; + size_t i, count = [array count]; + + for (i = 0; i < count; i++) + [cArray[i] release]; + + [array removeAllItems]; +} - (void)removeObjectsInRange: (of_range_t)range { id *cArray = [array cArray], *copy; size_t i, count = [array count]; Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -330,11 +330,11 @@ foundCharacters: characters]; [pool release]; } - [cache removeNItems: [cache count]]; + [cache removeAllItems]; *last = *i + 1; state = OF_XMLPARSER_TAG_OPENED; } @@ -492,11 +492,11 @@ [delegate parser: self foundProcessingInstructions: pi]; [pool release]; - [cache removeNItems: [cache count]]; + [cache removeAllItems]; *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } else level = 0; @@ -586,11 +586,11 @@ pool = [[OFAutoreleasePool alloc] init]; [namespaces addObject: [OFMutableDictionary dictionary]]; [pool release]; } - [cache removeNItems: [cache count]]; + [cache removeAllItems]; *last = *i + 1; } /* Inside a close tag, no name yet */ - (void)_parseInCloseTagNameWithBuffer: (const char*)buffer @@ -633,11 +633,11 @@ @throw [OFMalformedXMLException exceptionWithClass: isa parser: self]; [previous removeLastObject]; - [cache removeNItems: [cache count]]; + [cache removeAllItems]; ns = namespace_for_prefix(prefix, namespaces); if (prefix != nil && ns == nil) @throw [OFUnboundNamespaceException exceptionWithClass: isa prefix: prefix]; @@ -775,11 +775,11 @@ attributePrefix = nil; } [pool release]; - [cache removeNItems: [cache count]]; + [cache removeAllItems]; *last = *i + 1; state = OF_XMLPARSER_EXPECT_DELIM; } @@ -835,11 +835,11 @@ namespace: attributePrefix stringValue: attributeValue]]; [pool release]; - [cache removeNItems: [cache count]]; + [cache removeAllItems]; [attributeName release]; [attributePrefix release]; attributeName = attributePrefix = nil; *last = *i + 1; @@ -949,11 +949,11 @@ [delegate parser: self foundCDATA: CDATA]; [pool release]; - [cache removeNItems: [cache count]]; + [cache removeAllItems]; *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } @@ -1003,11 +1003,11 @@ [delegate parser: self foundComment: comment]; [pool release]; - [cache removeNItems: [cache count]]; + [cache removeAllItems]; *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; }