@@ -29,11 +29,10 @@ #import "OFFile.h" #import "OFURL.h" #import "OFHTTPRequest.h" #import "OFDataArray.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFHTTPRequestFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @@ -41,10 +40,11 @@ #import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" #import "of_asprintf.h" #import "unicode.h" /* @@ -871,28 +871,28 @@ } - initWithContentsOfURL: (OFURL*)URL encoding: (of_string_encoding_t)encoding { - OFAutoreleasePool *pool; + void *pool; OFHTTPRequest *request; OFHTTPRequestResult *result; OFString *contentType; Class c; c = [self class]; [self release]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); if ([[URL scheme] isEqual: @"file"]) { if (encoding == OF_STRING_ENCODING_AUTODETECT) encoding = OF_STRING_ENCODING_UTF_8; self = [[c alloc] initWithContentsOfFile: [URL path] encoding: encoding]; - [pool release]; + objc_autoreleasePoolPop(pool); return self; } request = [OFHTTPRequest requestWithURL: URL]; result = [request perform]; @@ -922,18 +922,18 @@ self = [[c alloc] initWithCString: (char*)[[result data] cArray] encoding: encoding length: [[result data] count]]; - [pool release]; + objc_autoreleasePoolPop(pool); return self; } - initWithSerialization: (OFXMLElement*)element { @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if (![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; @@ -950,11 +950,11 @@ selector: _cmd]; } self = [self initWithString: [element stringValue]]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -1082,11 +1082,11 @@ buffer[i] = [self characterAtIndex: range.start + i]; } - (BOOL)isEqual: (id)object { - OFAutoreleasePool *pool; + void *pool; OFString *otherString; const of_unichar_t *unicodeString, *otherUnicodeString; size_t length; if (object == self) @@ -1099,22 +1099,22 @@ length = [self length]; if ([otherString length] != length) return NO; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; otherUnicodeString = [otherString unicodeString]; if (memcmp(unicodeString, otherUnicodeString, length * sizeof(of_unichar_t))) { - [pool release]; + objc_autoreleasePoolPop(pool); return NO; } - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } - copy @@ -1127,11 +1127,11 @@ return [[OFMutableString alloc] initWithString: self]; } - (of_comparison_result_t)compare: (id)object { - OFAutoreleasePool *pool; + void *pool; OFString *otherString; const of_unichar_t *unicodeString, *otherUnicodeString; size_t i, minimumLength; if (object == self) @@ -1144,28 +1144,28 @@ otherString = object; minimumLength = ([self length] > [otherString length] ? [otherString length] : [self length]); - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; otherUnicodeString = [otherString unicodeString]; for (i = 0; i < minimumLength; i++) { if (unicodeString[i] > otherUnicodeString[i]) { - [pool release]; + objc_autoreleasePoolPop(pool); return OF_ORDERED_DESCENDING; } if (unicodeString[i] < otherUnicodeString[i]) { - [pool release]; + objc_autoreleasePoolPop(pool); return OF_ORDERED_ASCENDING; } } - [pool release]; + objc_autoreleasePoolPop(pool); if ([self length] > [otherString length]) return OF_ORDERED_DESCENDING; if ([self length] < [otherString length]) return OF_ORDERED_ASCENDING; @@ -1173,11 +1173,11 @@ return OF_ORDERED_SAME; } - (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *string, *otherUnicodeString; size_t i, length, otherLength, minimumLength; if (otherString == self) return OF_ORDERED_SAME; @@ -1208,20 +1208,20 @@ if (tc) oc = tc; } if (c > oc) { - [pool release]; + objc_autoreleasePoolPop(pool); return OF_ORDERED_DESCENDING; } if (c < oc) { - [pool release]; + objc_autoreleasePoolPop(pool); return OF_ORDERED_ASCENDING; } } - [pool release]; + objc_autoreleasePoolPop(pool); if (length > otherLength) return OF_ORDERED_DESCENDING; if (length < otherLength) return OF_ORDERED_ASCENDING; @@ -1255,11 +1255,11 @@ return [[self copy] autorelease]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; OFString *className; if ([self isKindOfClass: [OFMutableString class]]) className = @"OFMutableString"; @@ -1269,14 +1269,14 @@ element = [OFXMLElement elementWithName: className namespace: OF_SERIALIZATION_NS stringValue: self]; [element retain]; - [pool release]; - [element autorelease]; - return element; + objc_autoreleasePoolPop(pool); + + return [element autorelease]; } - (OFString*)JSONRepresentation { OFMutableString *JSON = [[self mutableCopy] autorelease]; @@ -1305,116 +1305,116 @@ return JSON; } - (size_t)indexOfFirstOccurrenceOfString: (OFString*)string { - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *unicodeString, *searchString; size_t i, length, searchLength; if ((searchLength = [string length]) == 0) return [self length]; if (searchLength > (length = [self length])) return OF_INVALID_INDEX; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; searchString = [string unicodeString]; for (i = 0; i <= length - searchLength; i++) { if (!memcmp(unicodeString + i, searchString, searchLength * sizeof(of_unichar_t))) { - [pool release]; + objc_autoreleasePoolPop(pool); return i; } } - [pool release]; + objc_autoreleasePoolPop(pool); return OF_INVALID_INDEX; } - (size_t)indexOfLastOccurrenceOfString: (OFString*)string { - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *unicodeString, *searchString; size_t i, length, searchLength; if ((searchLength = [string length]) == 0) return [self length]; if (searchLength > (length = [self length])) return OF_INVALID_INDEX; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; searchString = [string unicodeString]; for (i = length - searchLength;; i--) { if (!memcmp(unicodeString + i, searchString, searchLength * sizeof(of_unichar_t))) { - [pool release]; + objc_autoreleasePoolPop(pool); return i; } /* Did not match and we're at the last character */ if (i == 0) break; } - [pool release]; + objc_autoreleasePoolPop(pool); return OF_INVALID_INDEX; } - (BOOL)containsString: (OFString*)string { - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *unicodeString, *searchString; size_t i, length, searchLength; if ((searchLength = [string length]) == 0) return YES; if (searchLength > (length = [self length])) return NO; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; searchString = [string unicodeString]; for (i = 0; i <= length - searchLength; i++) { if (!memcmp(unicodeString + i, searchString, searchLength * sizeof(of_unichar_t))) { - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } } - [pool release]; + objc_autoreleasePoolPop(pool); return NO; } - (OFString*)substringWithRange: (of_range_t)range { - OFAutoreleasePool *pool; + void *pool; OFString *ret; if (range.start + range.length > [self length]) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); ret = [[OFString alloc] initWithUnicodeString: [self unicodeString] + range.start length: range.length]; - [pool release]; + objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString*)stringByAppendingString: (OFString*)string @@ -1550,22 +1550,20 @@ return NO; tmp = [self allocMemoryWithSize: sizeof(of_unichar_t) count: prefixLength]; @try { - OFAutoreleasePool *pool; + void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(0, prefixLength)]; - pool = [[OFAutoreleasePool alloc] init]; - prefixString = [prefix unicodeString]; compare = memcmp(tmp, prefixString, prefixLength * sizeof(of_unichar_t)); - [pool release]; + objc_autoreleasePoolPop(pool); } @finally { [self freeMemory: tmp]; } return !compare; @@ -1584,23 +1582,21 @@ length = [self length]; tmp = [self allocMemoryWithSize: sizeof(of_unichar_t) count: suffixLength]; @try { - OFAutoreleasePool *pool; + void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(length - suffixLength, suffixLength)]; - pool = [[OFAutoreleasePool alloc] init]; - suffixString = [suffix unicodeString]; compare = memcmp(tmp, suffixString, suffixLength * sizeof(of_unichar_t)); - [pool release]; + objc_autoreleasePoolPop(pool); } @finally { [self freeMemory: tmp]; } return !compare; @@ -1613,28 +1609,28 @@ } - (OFArray*)componentsSeparatedByString: (OFString*)delimiter skipEmpty: (BOOL)skipEmpty { - OFAutoreleasePool *pool; + void *pool; OFMutableArray *array = [OFMutableArray array]; const of_unichar_t *string, *delimiterString; size_t length = [self length]; size_t delimiterLength = [delimiter length]; size_t i, last; OFString *component; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); string = [self unicodeString]; delimiterString = [delimiter unicodeString]; if (delimiterLength > length) { [array addObject: [[self copy] autorelease]]; [array makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return array; } for (i = 0, last = 0; i <= length - delimiterLength; i++) { @@ -1653,28 +1649,28 @@ if (!skipEmpty || ![component isEqual: @""]) [array addObject: component]; [array makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return array; } - (OFArray*)pathComponents { OFMutableArray *ret; - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *string; size_t i, last = 0, length = [self length]; ret = [OFMutableArray array]; if (length == 0) return ret; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); string = [self unicodeString]; #ifndef _WIN32 if (string[length - 1] == OF_PATH_DELIMITER) @@ -1698,26 +1694,26 @@ [ret addObject: [self substringWithRange: of_range(last, i - last)]]; [ret makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return ret; } - (OFString*)lastPathComponent { - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *string; size_t length = [self length]; ssize_t i; if (length == 0) return @""; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); string = [self unicodeString]; #ifndef _WIN32 if (string[length - 1] == OF_PATH_DELIMITER) @@ -1735,11 +1731,11 @@ i++; break; } } - [pool release]; + objc_autoreleasePoolPop(pool); /* * Only one component, but the trailing delimiter might have been * removed, so return a new string anyway. */ @@ -1749,18 +1745,18 @@ return [self substringWithRange: of_range(i, length - i)]; } - (OFString*)stringByDeletingLastPathComponent { - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *string; size_t i, length = [self length]; if (length == 0) return @""; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); string = [self unicodeString]; #ifndef _WIN32 if (string[length - 1] == OF_PATH_DELIMITER) @@ -1768,42 +1764,42 @@ if (string[length - 1] == '/' || string[length - 1] == '\\') #endif length--; if (length == 0) { - [pool release]; + objc_autoreleasePoolPop(pool); return [self substringWithRange: of_range(0, 1)]; } for (i = length - 1; i >= 1; i--) { #ifndef _WIN32 if (string[i] == OF_PATH_DELIMITER) { #else if (string[i] == '/' || string[i] == '\\') { #endif - [pool release]; + objc_autoreleasePoolPop(pool); return [self substringWithRange: of_range(0, i)]; } } #ifndef _WIN32 if (string[0] == OF_PATH_DELIMITER) { #else if (string[0] == '/' || string[0] == '\\') { #endif - [pool release]; + objc_autoreleasePoolPop(pool); return [self substringWithRange: of_range(0, 1)]; } - [pool release]; + objc_autoreleasePoolPop(pool); return @"."; } - (intmax_t)decimalValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *string = [self unicodeString]; size_t length = [self length]; int i = 0; intmax_t value = 0; BOOL expectWhitespace = NO; @@ -1813,11 +1809,11 @@ string++; length--; } if (length == 0) { - [pool release]; + objc_autoreleasePoolPop(pool); return 0; } if (string[0] == '-' || string[0] == '+') i++; @@ -1849,18 +1845,18 @@ } if (string[0] == '-') value *= -1; - [pool release]; + objc_autoreleasePoolPop(pool); return value; } - (uintmax_t)hexadecimalValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *string = [self unicodeString]; size_t length = [self length]; int i = 0; uintmax_t value = 0; BOOL expectWhitespace = NO, foundValue = NO; @@ -1870,11 +1866,11 @@ string++; length--; } if (length == 0) { - [pool release]; + objc_autoreleasePoolPop(pool); return 0; } if (length >= 2 && string[0] == '0' && string[1] == 'x') i = 2; @@ -1920,18 +1916,18 @@ if (!foundValue) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - [pool release]; + objc_autoreleasePoolPop(pool); return value; } - (float)floatValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const char *cString = [self UTF8String]; char *endPointer = NULL; float value; while (*cString == ' ' || *cString == '\t' || *cString == '\n' || @@ -1947,18 +1943,18 @@ *endPointer != '\n' && *endPointer != '\r' && *endPointer != '\f') @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - [pool release]; + objc_autoreleasePoolPop(pool); return value; } - (double)doubleValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const char *cString = [self UTF8String]; char *endPointer = NULL; double value; while (*cString == ' ' || *cString == '\t' || *cString == '\n' || @@ -1974,11 +1970,11 @@ *endPointer != '\n' && *endPointer != '\r' && *endPointer != '\f') @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - [pool release]; + objc_autoreleasePoolPop(pool); return value; } - (const of_unichar_t*)unicodeString @@ -1997,11 +1993,11 @@ } - (const uint16_t*)UTF16String { OFObject *object = [[[OFObject alloc] init] autorelease]; - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *unicodeString = [self unicodeString]; size_t length = [self length]; uint16_t *ret; size_t i, j; @@ -2034,59 +2030,59 @@ count: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } - [pool release]; + objc_autoreleasePoolPop(pool); return ret; } - (void)writeToFile: (OFString*)path { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFFile *file; file = [OFFile fileWithPath: path mode: @"wb"]; [file writeString: self]; - [pool release]; + objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *string = [self unicodeString]; size_t i, last = 0, length = [self length]; BOOL stop = NO, lastCarriageReturn = NO; - pool2 = [[OFAutoreleasePool alloc] init]; - for (i = 0; i < length && !stop; i++) { if (lastCarriageReturn && string[i] == '\n') { lastCarriageReturn = NO; last++; continue; } if (string[i] == '\n' || string[i] == '\r') { + void *pool2 = objc_autoreleasePoolPush(); + block([self substringWithRange: of_range(last, i - last)], &stop); last = i + 1; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } lastCarriageReturn = (string[i] == '\r'); } if (!stop) block([self substringWithRange: of_range(last, i - last)], &stop); - [pool release]; + objc_autoreleasePoolPop(pool); } #endif @end