@@ -24,20 +24,20 @@ #include #import "OFString_UTF8.h" #import "OFMutableString_UTF8.h" #import "OFArray.h" -#import "OFAutoreleasePool.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" #import "of_asprintf.h" #import "unicode.h" extern const uint16_t of_iso_8859_15[256]; @@ -820,17 +820,17 @@ - (void)getCharacters: (of_unichar_t*)buffer inRange: (of_range_t)range { /* TODO: Could be slightly optimized */ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *unicodeString = [self unicodeString]; memcpy(buffer, unicodeString + range.start, range.length * sizeof(of_unichar_t)); - [pool release]; + objc_autoreleasePoolPop(pool); } - (size_t)indexOfFirstOccurrenceOfString: (OFString*)string { const char *cString = [string UTF8String]; @@ -930,23 +930,23 @@ } - (OFArray*)componentsSeparatedByString: (OFString*)delimiter skipEmpty: (BOOL)skipEmpty { - OFAutoreleasePool *pool; + void *pool; OFMutableArray *array; const char *cString = [delimiter UTF8String]; size_t cStringLength = [delimiter UTF8StringLength]; size_t i, last; OFString *component; array = [OFMutableArray array]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); if (cStringLength > s->cStringLength) { [array addObject: [[self copy] autorelease]]; - [pool release]; + objc_autoreleasePoolPop(pool); return array; } for (i = 0, last = 0; i <= s->cStringLength - cStringLength; i++) { @@ -965,27 +965,27 @@ if (!skipEmpty || ![component isEqual: @""]) [array addObject: component]; [array makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return array; } - (OFArray*)pathComponents { OFMutableArray *ret; - OFAutoreleasePool *pool; + void *pool; size_t i, last = 0, pathCStringLength = s->cStringLength; ret = [OFMutableArray array]; if (pathCStringLength == 0) return ret; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); #ifndef _WIN32 if (s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER) #else if (s->cString[pathCStringLength - 1] == '/' || @@ -1009,11 +1009,11 @@ [ret addObject: [OFString stringWithUTF8String: s->cString + last length: i - last]]; [ret makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return ret; } - (OFString*)lastPathComponent @@ -1126,11 +1126,11 @@ } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool; const char *cString = s->cString; const char *last = cString; BOOL stop = NO, lastCarriageReturn = NO; while (!stop && *cString != 0) { @@ -1142,25 +1142,29 @@ continue; } if (*cString == '\n' || *cString == '\r') { + pool = objc_autoreleasePoolPush(); + block([OFString stringWithUTF8String: last length: cString - last], &stop); last = cString + 1; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } lastCarriageReturn = (*cString == '\r'); cString++; } + pool = objc_autoreleasePoolPush(); + if (!stop) block([OFString stringWithUTF8String: last length: cString - last], &stop); - [pool release]; + objc_autoreleasePoolPop(pool); } #endif @end