@@ -27,18 +27,18 @@ #import "OFXMLAttribute.h" #import "OFXMLCharacters.h" #import "OFXMLCDATA.h" #import "OFXMLParser.h" #import "OFXMLElementBuilder.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFMalformedXMLException.h" #import "OFNotImplementedException.h" #import "OFUnboundNamespaceException.h" +#import "autorelease.h" #import "macros.h" /* References for static linking */ void _references_to_categories_of_OFXMLElement(void) { @@ -208,11 +208,11 @@ return self; } - initWithXMLString: (OFString*)string { - OFAutoreleasePool *pool; + void *pool; OFXMLParser *parser; OFXMLElementBuilder *builder; OFXMLElement_OFXMLElementBuilderDelegate *delegate; Class c; @@ -221,11 +221,11 @@ if (string == nil) @throw [OFInvalidArgumentException exceptionWithClass: c selector: _cmd]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; builder = [OFXMLElementBuilder elementBuilder]; delegate = [[[OFXMLElement_OFXMLElementBuilderDelegate alloc] init] autorelease]; @@ -239,27 +239,27 @@ @throw [OFMalformedXMLException exceptionWithClass: c parser: parser]; self = [delegate->element retain]; - [pool release]; + objc_autoreleasePoolPop(pool); return self; } - initWithFile: (OFString*)path { - OFAutoreleasePool *pool; + void *pool; OFXMLParser *parser; OFXMLElementBuilder *builder; OFXMLElement_OFXMLElementBuilderDelegate *delegate; Class c; c = [self class]; [self release]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; builder = [OFXMLElementBuilder elementBuilder]; delegate = [[[OFXMLElement_OFXMLElementBuilderDelegate alloc] init] autorelease]; @@ -273,21 +273,21 @@ @throw [OFMalformedXMLException exceptionWithClass: c parser: parser]; self = [delegate->element retain]; - [pool release]; + objc_autoreleasePoolPop(pool); return self; } - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *attributesElement, *namespacesElement; OFXMLElement *childrenElement; OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; @@ -369,11 +369,11 @@ if (name == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -420,58 +420,57 @@ OF_GETTER(children, YES) } - (void)setStringValue: (OFString*)stringValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [self setChildren: [OFArray arrayWithObject: [OFXMLCharacters charactersWithString: stringValue]]]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (OFString*)stringValue { - OFAutoreleasePool *pool; OFMutableString *ret; OFXMLElement **objects; size_t i, count = [children count]; if (count == 0) return @""; ret = [OFMutableString string]; objects = [children objects]; - pool = [[OFAutoreleasePool alloc] init]; for (i = 0; i < count; i++) { + void *pool = objc_autoreleasePoolPush(); + [ret appendString: [objects[i] stringValue]]; - [pool releaseObjects]; + + objc_autoreleasePoolPop(pool); } [ret makeImmutable]; - [pool release]; - return ret; } - (OFString*)_XMLStringWithParent: (OFXMLElement*)parent namespaces: (OFDictionary*)allNamespaces indentation: (unsigned int)indentation level: (unsigned int)level { - OFAutoreleasePool *pool, *pool2; + void *pool; char *cString; size_t length, i, j, attributesCount; OFString *prefix, *parentPrefix; OFXMLAttribute **attributesObjects; OFString *ret; OFString *defaultNS; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); parentPrefix = [allNamespaces objectForKey: (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")]; /* Add the namespaces of the current element */ @@ -552,12 +551,12 @@ /* Attributes */ attributesObjects = [attributes objects]; attributesCount = [attributes count]; - pool2 = [[OFAutoreleasePool alloc] init]; for (j = 0; j < attributesCount; j++) { + void *pool2 = objc_autoreleasePoolPush(); OFString *attributeName = [attributesObjects[j] name]; OFString *attributePrefix = nil; OFString *tmp = [[attributesObjects[j] stringValue] stringByXMLEscaping]; @@ -596,11 +595,11 @@ cString[i++] = '\''; memcpy(cString + i, [tmp UTF8String], [tmp UTF8StringLength]); i += [tmp UTF8StringLength]; cString[i++] = '\''; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } /* Childen */ if (children != nil) { OFXMLElement **childrenObjects = [children objects]; @@ -691,11 +690,11 @@ cString[i++] = '/'; cString[i++] = '>'; assert(i == length); - [pool release]; + objc_autoreleasePoolPop(pool); @try { ret = [OFString stringWithUTF8String: cString length: length]; } @finally { @@ -729,11 +728,11 @@ level: level]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; @@ -789,14 +788,14 @@ [childrenElement addChild: [children XMLElementBySerializing]]; [element addChild: childrenElement]; } [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } - (void)addAttribute: (OFXMLAttribute*)attribute { if (attributes == nil) @@ -817,17 +816,17 @@ - (void)addAttributeWithName: (OFString*)name_ namespace: (OFString*)ns_ stringValue: (OFString*)stringValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [self addAttribute: [OFXMLAttribute attributeWithName: name_ namespace: ns_ stringValue: stringValue]]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (OFXMLAttribute*)attributeForName: (OFString*)attributeName { OFXMLAttribute **objects = [attributes objects];