Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -559,12 +559,10 @@ - (OFString*)OF_JSONRepresentationWithOptions: (int)options depth: (size_t)depth { OFMutableString *JSON = [OFMutableString stringWithString: @"["]; void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [self objectEnumerator]; - id object; size_t i, count = [self count]; if (options & OF_JSON_REPRESENTATION_PRETTY) { OFMutableString *indentation = [OFMutableString string]; @@ -572,11 +570,11 @@ [indentation appendString: @"\t"]; [JSON appendString: @"\n"]; i = 0; - while ((object = [enumerator nextObject]) != nil) { + for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [JSON appendString: indentation]; [JSON appendString: @"\t"]; [JSON appendString: [object @@ -592,11 +590,11 @@ } [JSON appendString: indentation]; } else { i = 0; - while ((object = [enumerator nextObject]) != nil) { + for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [JSON appendString: [object OF_JSONRepresentationWithOptions: options depth: depth + 1]]; @@ -619,12 +617,10 @@ - (OFDataArray*)messagePackRepresentation { OFDataArray *data; size_t i, count; void *pool; - OFEnumerator *enumerator; - id object; data = [OFDataArray dataArray]; count = [self count]; if (count <= 15) { @@ -648,12 +644,11 @@ @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); i = 0; - enumerator = [self objectEnumerator]; - while ((object = [enumerator nextObject]) != nil) { + for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); OFDataArray *child; i++; @@ -753,11 +748,11 @@ { return [[[OFArrayEnumerator alloc] initWithArray: self mutationsPtr: NULL] autorelease]; } -#if defined(OF_HAVE_BLOCKS) && defined(OF_HAVE_FAST_ENUMERATION) +#ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { size_t i = 0; bool stop = false; Index: src/OFArray_adjacent.m ================================================================== --- src/OFArray_adjacent.m +++ src/OFArray_adjacent.m @@ -165,22 +165,18 @@ { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator; - OFXMLElement *child; if ((![[element name] isEqual: @"OFArray"] && ![[element name] isEqual: @"OFMutableArray"]) || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exception]; - enumerator = [[element elementsForNamespace: - OF_SERIALIZATION_NS] objectEnumerator]; - - while ((child = [enumerator nextObject]) != nil) { + for (OFXMLElement *child in + [element elementsForNamespace: OF_SERIALIZATION_NS]) { void *pool2 = objc_autoreleasePoolPush(); id object; object = [child objectByDeserializing]; [_array addItem: &object]; Index: src/OFCountedSet.m ================================================================== --- src/OFCountedSet.m +++ src/OFCountedSet.m @@ -141,24 +141,21 @@ - (OFString*)description { OFMutableString *ret; void *pool; - OFEnumerator *enumerator; size_t i, count = [self count]; - id object; if (count == 0) return @"{()}"; ret = [OFMutableString stringWithString: @"{(\n"]; pool = objc_autoreleasePoolPush(); - enumerator = [self objectEnumerator]; i = 0; - while ((object = [enumerator nextObject]) != nil) { + for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [ret appendString: object]; [ret appendFormat: @": %zu", [self countForObject: object]]; @@ -190,19 +187,15 @@ - (OFXMLElement*)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; - OFEnumerator *enumerator; - id object; element = [OFXMLElement elementWithName: @"OFCountedSet" namespace: OF_SERIALIZATION_NS]; - enumerator = [self objectEnumerator]; - - while ((object = [enumerator nextObject]) != nil) { + for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *objectElement; OFString *count; @@ -242,26 +235,20 @@ { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)set; - OFEnumerator *enumerator = [countedSet objectEnumerator]; - id object; - while ((object = [enumerator nextObject]) != nil) { + for (id object in countedSet) { size_t i, count = [countedSet countForObject: object]; for (i = 0; i < count; i++) [self removeObject: object]; } - } else { - OFEnumerator *enumerator = [set objectEnumerator]; - id object; - - while ((object = [enumerator nextObject]) != nil) + } else + for (id object in set) [self removeObject: object]; - } objc_autoreleasePoolPop(pool); } - (void)unionSet: (OFSet*)set @@ -268,25 +255,19 @@ { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)set; - OFEnumerator *enumerator = [countedSet objectEnumerator]; - id object; - while ((object = [enumerator nextObject]) != nil) { + for (id object in countedSet) { size_t i, count = [countedSet countForObject: object]; for (i = 0; i < count; i++) [self addObject: object]; } - } else { - OFEnumerator *enumerator = [set objectEnumerator]; - id object; - - while ((object = [enumerator nextObject]) != nil) + } else + for (id object in set) [self addObject: object]; - } objc_autoreleasePoolPop(pool); } @end Index: src/OFCountedSet_hashtable.m ================================================================== --- src/OFCountedSet_hashtable.m +++ src/OFCountedSet_hashtable.m @@ -43,29 +43,22 @@ @try { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)countedSet; - OFEnumerator *enumerator = - [countedSet objectEnumerator]; - id object; - while ((object = [enumerator nextObject]) != nil) { + for (id object in countedSet) { size_t i, count; count = [countedSet countForObject: object]; for (i = 0; i < count; i++) [self addObject: object]; } - } else { - OFEnumerator *enumerator = [set objectEnumerator]; - id object; - - while ((object = [enumerator nextObject]) != nil) + } else + for (id object in set) [self addObject: object]; - } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -134,23 +127,18 @@ { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); - OFArray *objects; - OFEnumerator *enumerator; - OFXMLElement *objectElement; if (![[element name] isEqual: @"OFCountedSet"] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exception]; - objects = [element elementsForName: @"object" - namespace: OF_SERIALIZATION_NS]; - - enumerator = [objects objectEnumerator]; - while ((objectElement = [enumerator nextObject]) != nil) { + for (OFXMLElement *objectElement in + [element elementsForName: @"object" + namespace: OF_SERIALIZATION_NS]) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *object; OFXMLAttribute *count_; size_t count; Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -299,11 +299,11 @@ - (bool)isEqual: (id)object { OFDictionary *otherDictionary; void *pool; - OFEnumerator *enumerator; + OFEnumerator *keyEnumerator, *objectEnumerator; id key; if (![object isKindOfClass: [OFDictionary class]]) return false; @@ -312,16 +312,17 @@ if ([otherDictionary count] != [self count]) return false; pool = objc_autoreleasePoolPush(); - enumerator = [self keyEnumerator]; - while ((key = [enumerator nextObject]) != nil) { - id object = [otherDictionary objectForKey: key]; + keyEnumerator = [self keyEnumerator]; + objectEnumerator = [self objectEnumerator]; + while ((key = [keyEnumerator nextObject]) != nil && + (object = [objectEnumerator nextObject]) != nil) { + id otherObject = [otherDictionary objectForKey: key]; - if (object == nil || - ![object isEqual: [self objectForKey: key]]) { + if (otherObject == nil || ![otherObject isEqual: object]) { objc_autoreleasePoolPop(pool); return false; } } @@ -338,12 +339,12 @@ if (object == nil) return false; pool = objc_autoreleasePoolPush(); + enumerator = [self objectEnumerator]; - while ((currentObject = [enumerator nextObject]) != nil) { if ([currentObject isEqual: object]) { objc_autoreleasePoolPop(pool); return true; } @@ -362,12 +363,12 @@ if (object == nil) return false; pool = objc_autoreleasePoolPush(); + enumerator = [self objectEnumerator]; - while ((currentObject = [enumerator nextObject]) != nil) { if (currentObject == object) { objc_autoreleasePoolPop(pool); return true; } @@ -379,21 +380,16 @@ } - (OFArray*)allKeys { OFMutableArray *ret = [OFMutableArray arrayWithCapacity: [self count]]; - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [self keyEnumerator]; - id key; - while ((key = [enumerator nextObject]) != nil) + for (id key in self) [ret addObject: key]; [ret makeImmutable]; - objc_autoreleasePoolPop(pool); - return ret; } - (OFArray*)allObjects { @@ -427,11 +423,11 @@ count: (int)count_ { OF_UNRECOGNIZED_SELECTOR } -#if defined(OF_HAVE_BLOCKS) && defined(OF_HAVE_FAST_ENUMERATION) +#ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (of_dictionary_enumeration_block_t)block { bool stop = false; @@ -440,13 +436,11 @@ if (stop) break; } } -#endif -#ifdef OF_HAVE_BLOCKS - (OFDictionary*)mappedDictionaryUsingBlock: (of_dictionary_map_block_t)block { OFMutableDictionary *new = [OFMutableDictionary dictionary]; [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, @@ -479,17 +473,19 @@ #endif - (uint32_t)hash { void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [self keyEnumerator]; - id key; + OFEnumerator *keyEnumerator = [self keyEnumerator]; + OFEnumerator *objectEnumerator = [self objectEnumerator]; + id key, object; uint32_t hash = 0; - while ((key = [enumerator nextObject]) != nil) { + while ((key = [keyEnumerator nextObject]) != nil && + (object = [objectEnumerator nextObject]) != nil) { hash += [key hash]; - hash += [[self objectForKey: key] hash]; + hash += [object hash]; } objc_autoreleasePoolPop(pool); return hash; Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -248,29 +248,22 @@ } - (void)createDirectoryAtPath: (OFString*)path createParents: (bool)createParents { - void *pool; - OFArray *pathComponents; - OFString *currentPath = nil, *component; - OFEnumerator *enumerator; + OFString *currentPath = nil; if (!createParents) { [self createDirectoryAtPath: path]; return; } if (path == nil) @throw [OFInvalidArgumentException exception]; - pool = objc_autoreleasePoolPush(); - - pathComponents = [path pathComponents]; - enumerator = [pathComponents objectEnumerator]; - while ((component = [enumerator nextObject]) != nil) { - void *pool2 = objc_autoreleasePoolPush(); + for (OFString *component in [path pathComponents]) { + void *pool = objc_autoreleasePoolPush(); if (currentPath != nil) currentPath = [currentPath stringByAppendingPathComponent: component]; else @@ -280,16 +273,14 @@ ![self directoryExistsAtPath: currentPath]) [self createDirectoryAtPath: currentPath]; [currentPath retain]; - objc_autoreleasePoolPop(pool2); + objc_autoreleasePoolPop(pool); [currentPath autorelease]; } - - objc_autoreleasePoolPop(pool); } - (OFArray*)contentsOfDirectoryAtPath: (OFString*)path { OFMutableArray *files; @@ -593,12 +584,10 @@ destinationPath: destination errNo: errno]; if (S_ISDIR(s.st_mode)) { OFArray *contents; - OFEnumerator *enumerator; - OFString *item; @try { [self createDirectoryAtPath: destination]; #ifdef OF_HAVE_CHMOD [self changePermissionsOfItemAtPath: destination @@ -620,12 +609,11 @@ errNo: [e errNo]]; @throw e; } - enumerator = [contents objectEnumerator]; - while ((item = [enumerator nextObject]) != nil) { + for (OFString *item in contents) { void *pool2 = objc_autoreleasePoolPush(); OFString *sourcePath, *destinationPath; sourcePath = [source stringByAppendingPathComponent: item]; @@ -790,12 +778,10 @@ @throw [OFRemoveItemFailedException exceptionWithPath: path errNo: errno]; if (S_ISDIR(s.st_mode)) { OFArray *contents; - OFEnumerator *enumerator; - OFString *item; @try { contents = [self contentsOfDirectoryAtPath: path]; } @catch (id e) { /* @@ -811,12 +797,11 @@ errNo: [e errNo]]; @throw e; } - enumerator = [contents objectEnumerator]; - while ((item = [enumerator nextObject]) != nil) { + for (OFString *item in contents) { void *pool2 = objc_autoreleasePoolPush(); [self removeItemAtPath: [path stringByAppendingPathComponent: item]]; Index: src/OFINICategory.m ================================================================== --- src/OFINICategory.m +++ src/OFINICategory.m @@ -190,32 +190,21 @@ } - (OFString*)stringForKey: (OFString*)key defaultValue: (OFString*)defaultValue { - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [_lines objectEnumerator]; - id line; - - while ((line = [enumerator nextObject]) != nil) { + for (id line in _lines) { OFINICategory_Pair *pair; if (![line isKindOfClass: [OFINICategory_Pair class]]) continue; pair = line; - if ([pair->_key isEqual: key]) { - OFString *value = [pair->_value copy]; - - objc_autoreleasePoolPop(pool); - - return [value autorelease]; - } - } - - objc_autoreleasePoolPop(pool); + if ([pair->_key isEqual: key]) + return [[pair->_value copy] autorelease]; + } return defaultValue; } - (intmax_t)integerForKey: (OFString*)key @@ -300,14 +289,12 @@ - (OFArray*)arrayForKey: (OFString*)key { OFMutableArray *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [_lines objectEnumerator]; - id line; - while ((line = [enumerator nextObject]) != nil) { + for (id line in _lines) { OFINICategory_Pair *pair; if (![line isKindOfClass: [OFINICategory_Pair class]]) continue; @@ -326,15 +313,13 @@ - (void)setString: (OFString*)string forKey: (OFString*)key { void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [_lines objectEnumerator]; OFINICategory_Pair *pair; - id line; - while ((line = [enumerator nextObject]) != nil) { + for (id line in _lines) { if (![line isKindOfClass: [OFINICategory_Pair class]]) continue; pair = line; @@ -348,13 +333,23 @@ return; } } pair = [[[OFINICategory_Pair alloc] init] autorelease]; - pair->_key = [key copy]; - pair->_value = [string copy]; - [_lines addObject: pair]; + pair->_key = nil; + pair->_value = nil; + + @try { + pair->_key = [key copy]; + pair->_value = [string copy]; + [_lines addObject: pair]; + } @catch (id e) { + [pair->_key release]; + [pair->_value release]; + + @throw e; + } objc_autoreleasePoolPop(pool); } - (void)setInteger: (intmax_t)integer @@ -399,13 +394,11 @@ - (void)setArray: (OFArray*)array forKey: (OFString*)key { void *pool; - OFEnumerator *enumerator; OFMutableArray *pairs; - id object; id const *lines; size_t i, count; bool replaced; if ([array count] == 0) { @@ -413,14 +406,13 @@ return; } pool = objc_autoreleasePoolPush(); - enumerator = [array objectEnumerator]; pairs = [OFMutableArray arrayWithCapacity: [array count]]; - while ((object = [enumerator nextObject]) != nil) { + for (id object in array) { OFINICategory_Pair *pair; if (![object isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; @@ -499,23 +491,19 @@ - (bool)OF_writeToStream: (OFStream*)stream encoding: (of_string_encoding_t)encoding first: (bool)first { - OFEnumerator *enumerator; - id line; - if ([_lines count] == 0) return false; if (first) [stream writeFormat: @"[%@]\n", _name]; else [stream writeFormat: @"\n[%@]\n", _name]; - enumerator = [_lines objectEnumerator]; - while ((line = [enumerator nextObject]) != nil) { + for (id line in _lines) { if ([line isKindOfClass: [OFINICategory_Comment class]]) { OFINICategory_Comment *comment = line; [stream writeLine: comment->_comment]; } else if ([line isKindOfClass: [OFINICategory_Pair class]]) { OFINICategory_Pair *pair = line; Index: src/OFINIFile.m ================================================================== --- src/OFINIFile.m +++ src/OFINIFile.m @@ -104,14 +104,13 @@ } - (OFINICategory*)categoryForName: (OFString*)name { void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [_categories objectEnumerator]; OFINICategory *category; - while ((category = [enumerator nextObject]) != nil) { + for (category in _categories) { if ([[category name] isEqual: name]) { OFINICategory *ret = [category retain]; objc_autoreleasePoolPop(pool); @@ -187,18 +186,16 @@ encoding: (of_string_encoding_t)encoding { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; - OFEnumerator *enumerator = [_categories objectEnumerator]; - OFINICategory *category; bool first = true; - while ((category = [enumerator nextObject]) != nil) + for (OFINICategory *category in _categories) if ([category OF_writeToStream: file encoding: encoding first: first]) first = false; objc_autoreleasePoolPop(pool); } @end Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -40,20 +40,17 @@ { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator; - OFXMLElement *child; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exception]; - enumerator = [[element elementsForNamespace: - OF_SERIALIZATION_NS] objectEnumerator]; - while ((child = [enumerator nextObject]) != nil) { + for (OFXMLElement *child in + [element elementsForNamespace: OF_SERIALIZATION_NS]) { void *pool2 = objc_autoreleasePoolPush(); [self appendObject: [child objectByDeserializing]]; objc_autoreleasePoolPop(pool2); Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -219,24 +219,15 @@ } - (void)insertObjectsFromArray: (OFArray*)array atIndex: (size_t)index { - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [array objectEnumerator]; - size_t i, count = [array count]; - - for (i = 0; i < count; i++) { - id object = [enumerator nextObject]; - - assert(object != nil); - + size_t i = 0; + + for (id object in array) [self insertObject: object - atIndex: index + i]; - } - - objc_autoreleasePoolPop(pool); + atIndex: index + i++]; } - (void)replaceObjectAtIndex: (size_t)index withObject: (id)object { Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -182,15 +182,12 @@ } - (void)removeAllObjects { void *pool = objc_autoreleasePoolPush(); - OFArray *keys = [self allKeys]; - OFEnumerator *enumerator = [keys objectEnumerator]; - id key; - while ((key = [enumerator nextObject]) != nil) + for (id key in [self allKeys]) [self removeObjectForKey: key]; objc_autoreleasePoolPop(pool); } Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -142,18 +142,12 @@ OF_UNRECOGNIZED_SELECTOR } - (void)minusSet: (OFSet*)set { - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [set objectEnumerator]; - id object; - - while ((object = [enumerator nextObject]) != nil) + for (id object in set) [self removeObject: object]; - - objc_autoreleasePoolPop(pool); } - (void)intersectSet: (OFSet*)set { void *pool = objc_autoreleasePoolPush(); @@ -162,17 +156,14 @@ cArray = [self allocMemoryWithSize: sizeof(id) count: count]; @try { - OFEnumerator *enumerator; - id object; size_t i; i = 0; - enumerator = [self objectEnumerator]; - while ((object = [enumerator nextObject]) != nil) { + for (id object in self) { assert(i < count); cArray[i++] = object; } for (i = 0; i < count; i++) @@ -185,20 +176,13 @@ objc_autoreleasePoolPop(pool); } - (void)unionSet: (OFSet*)set { - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator; - id object; - - enumerator = [set objectEnumerator]; - while ((object = [enumerator nextObject]) != nil) + for (id object in set) [self addObject: object]; - - objc_autoreleasePoolPop(pool); } - (void)makeImmutable { } @end Index: src/OFProcess.m ================================================================== --- src/OFProcess.m +++ src/OFProcess.m @@ -228,12 +228,10 @@ SECURITY_ATTRIBUTES sa; PROCESS_INFORMATION pi; STARTUPINFOW si; void *pool; OFMutableString *argumentsString; - OFEnumerator *enumerator; - OFString *argument; of_char16_t *argumentsCopy; size_t length; sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; @@ -277,12 +275,11 @@ if ([argumentsString containsString: @" "]) { [argumentsString prependString: @"\""]; [argumentsString appendString: @"\""]; } - enumerator = [arguments objectEnumerator]; - while ((argument = [enumerator nextObject]) != nil) { + for (OFString *argument in arguments) { OFMutableString *tmp = [[argument mutableCopy] autorelease]; bool containsSpaces = [tmp containsString: @" "]; [argumentsString appendString: @" "]; Index: src/OFSet.m ================================================================== --- src/OFSet.m +++ src/OFSet.m @@ -246,15 +246,13 @@ } - (uint32_t)hash { void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [self objectEnumerator]; - id object; uint32_t hash = 0; - while ((object = [enumerator nextObject]) != nil) + for (id object in self) hash += [object hash]; objc_autoreleasePoolPop(pool); return hash; @@ -262,24 +260,21 @@ - (OFString*)description { void *pool; OFMutableString *ret; - OFEnumerator *enumerator; size_t i, count = [self count]; - id object; if (count == 0) return @"{()}"; ret = [OFMutableString stringWithString: @"{(\n"]; pool = objc_autoreleasePoolPush(); - enumerator = [self objectEnumerator]; i = 0; - while ((object = [enumerator nextObject]) != nil) { + for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [ret appendString: [object description]]; if (++i < count) @@ -308,63 +303,39 @@ return [[OFMutableSet alloc] initWithSet: self]; } - (bool)isSubsetOfSet: (OFSet*)set { - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator; - id object; - - enumerator = [self objectEnumerator]; - while ((object = [enumerator nextObject]) != nil) { - if (![set containsObject: object]) { - objc_autoreleasePoolPop(pool); + for (id object in self) + if (![set containsObject: object]) return false; - } - } - - objc_autoreleasePoolPop(pool); return true; } - (bool)intersectsSet: (OFSet*)set { - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator; - id object; - - enumerator = [self objectEnumerator]; - while ((object = [enumerator nextObject]) != nil) { - if ([set containsObject: object]) { - objc_autoreleasePoolPop(pool); + for (id object in self) + if ([set containsObject: object]) return true; - } - } - - objc_autoreleasePoolPop(pool); return false; } - (OFXMLElement*)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; - OFEnumerator *enumerator; - id object; if ([self isKindOfClass: [OFMutableSet class]]) element = [OFXMLElement elementWithName: @"OFMutableSet" namespace: OF_SERIALIZATION_NS]; else element = [OFXMLElement elementWithName: @"OFSet" namespace: OF_SERIALIZATION_NS]; - enumerator = [self objectEnumerator]; - - while ((object = [enumerator nextObject]) != nil) { + for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [element addChild: [object XMLElementBySerializing]]; objc_autoreleasePoolPop(pool2); @@ -429,11 +400,11 @@ objc_autoreleasePoolPop(pool); return [ret autorelease]; } -#if defined(OF_HAVE_BLOCKS) && defined(OF_HAVE_FAST_ENUMERATION) +#ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block { bool stop = false; for (id object in self) { @@ -441,13 +412,11 @@ if (stop) break; } } -#endif -#ifdef OF_HAVE_BLOCKS - (OFSet*)filteredSetUsingBlock: (of_set_filter_block_t)block { OFMutableSet *ret = [OFMutableSet set]; [self enumerateObjectsUsingBlock: ^ (id object, bool *stop) { Index: src/OFSet_hashtable.m ================================================================== --- src/OFSet_hashtable.m +++ src/OFSet_hashtable.m @@ -98,20 +98,13 @@ } self = [self initWithCapacity: count]; @try { - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator; - id object; - - enumerator = [set objectEnumerator]; - while ((object = [enumerator nextObject]) != nil) + for (id object in set) [_mapTable setValue: (void*)1 forKey: object]; - - objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -133,20 +126,13 @@ } self = [self initWithCapacity: count]; @try { - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator; - id object; - - enumerator = [array objectEnumerator]; - while ((object = [enumerator nextObject]) != nil) + for (id object in array) [_mapTable setValue: (void*)1 forKey: object]; - - objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -209,21 +195,18 @@ { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator; - OFXMLElement *child; if ((![[element name] isEqual: @"OFSet"] && ![[element name] isEqual: @"OFMutableSet"]) || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exception]; - enumerator = [[element elementsForNamespace: - OF_SERIALIZATION_NS] objectEnumerator]; - while ((child = [enumerator nextObject]) != nil) { + for (OFXMLElement *child in + [element elementsForNamespace: OF_SERIALIZATION_NS]) { void *pool2 = objc_autoreleasePoolPush(); [_mapTable setValue: (void*)1 forKey: [child objectByDeserializing]]; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -654,22 +654,20 @@ #endif + (OFString*)pathWithComponents: (OFArray*)components { OFMutableString *ret = [OFMutableString string]; - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [components objectEnumerator]; - OFString *component; - - if ((component = [enumerator nextObject]) != nil) - [ret appendString: component]; - while ((component = [enumerator nextObject]) != nil) { - [ret appendString: OF_PATH_DELIMITER_STRING]; - [ret appendString: component]; - } - - objc_autoreleasePoolPop(pool); + bool first = true; + + for (OFString *component in components) { + if (!first) + [ret appendString: OF_PATH_DELIMITER_STRING]; + + [ret appendString: component]; + + first = false; + } return ret; } - init Index: src/OFThreadPool.m ================================================================== --- src/OFThreadPool.m +++ src/OFThreadPool.m @@ -293,29 +293,24 @@ return self; } - (void)dealloc { - void *pool = objc_autoreleasePoolPush(); [_queueCondition lock]; @try { [_countCondition lock]; @try { - OFEnumerator *enumerator = [_threads objectEnumerator]; - OFThreadPoolThread *thread; - - while ((thread = [enumerator nextObject]) != nil) + for (OFThreadPoolThread *thread in _threads) thread->_terminate = true; } @finally { [_countCondition unlock]; } [_queueCondition broadcast]; } @finally { [_queueCondition unlock]; } - objc_autoreleasePoolPop(pool); [_threads release]; [_queue release]; [_queueCondition release]; [_countCondition release]; Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -319,12 +319,11 @@ ![_namespaces isKindOfClass: [OFMutableDictionary class]]) || (_children != nil && ![_children isKindOfClass: [OFMutableArray class]])) @throw [OFInvalidArgumentException exception]; - objectEnumerator = [_attributes objectEnumerator]; - while ((object = [objectEnumerator nextObject]) != nil) + for (object in _attributes) if (![object isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; keyEnumerator = [_namespaces keyEnumerator]; objectEnumerator = [_namespaces objectEnumerator]; @@ -332,12 +331,11 @@ (object = [objectEnumerator nextObject]) != nil) if (![key isKindOfClass: [OFString class]] || ![object isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; - objectEnumerator = [_children objectEnumerator]; - while ((object = [objectEnumerator nextObject]) != nil) + for (object in _children) if (![object isKindOfClass: [OFXMLNode class]]) @throw [OFInvalidArgumentException exception]; if (_namespaces == nil) _namespaces = [[OFMutableDictionary alloc] init]; @@ -918,22 +916,16 @@ } - (void)insertChildren: (OFArray*)children atIndex: (size_t)index { - void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [children objectEnumerator]; - OFXMLNode *node; - - while ((node = [enumerator nextObject]) != nil) + for (OFXMLNode *node in children) if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; [_children insertObjectsFromArray: children atIndex: index]; - - objc_autoreleasePoolPop(pool); } - (void)removeChild: (OFXMLNode*)child { if ([child isKindOfClass: [OFXMLAttribute class]]) Index: utils/ofhash/OFHash.m ================================================================== --- utils/ofhash/OFHash.m +++ utils/ofhash/OFHash.m @@ -71,28 +71,32 @@ @implementation OFHash - (void)applicationDidFinishLaunching { OFArray OF_GENERIC(OFString*) *arguments = [OFApplication arguments]; id hash; - OFEnumerator *enumerator; - OFString *path; + bool first = true; int exitStatus = 0; if ([arguments count] < 2) help(); if ((hash = hashForName([arguments firstObject])) == nil) help(); - enumerator = [[arguments objectsInRange: - of_range(1, [arguments count] - 1)] objectEnumerator]; - while ((path = [enumerator nextObject]) != nil) { - void *pool = objc_autoreleasePoolPush(); + for (OFString *path in arguments) { + void *pool; OFStream *file; const uint8_t *digest; size_t i, digestSize; + if (first) { + first = false; + continue; + } + + pool = objc_autoreleasePoolPush(); + if ([path isEqual: @"-"]) file = of_stdin; else { @try { file = [OFFile fileWithPath: path Index: utils/ofzip/OFZIP.m ================================================================== --- utils/ofzip/OFZIP.m +++ utils/ofzip/OFZIP.m @@ -252,16 +252,11 @@ return archive; } - (void)listFilesInArchive: (OFZIPArchive*)archive { - OFEnumerator OF_GENERIC(OFZIPArchiveEntry*) *enumerator; - OFZIPArchiveEntry *entry; - - enumerator = [[archive entries] objectEnumerator]; - - while ((entry = [enumerator nextObject]) != nil) { + for (OFZIPArchiveEntry *entry in [archive entries]) { void *pool = objc_autoreleasePoolPush(); [of_stdout writeLine: [entry fileName]]; if (_outputLevel >= 1) { @@ -311,26 +306,20 @@ - (void)extractFiles: (OFArray OF_GENERIC(OFString*)*)files fromArchive: (OFZIPArchive*)archive { OFFileManager *fileManager = [OFFileManager defaultManager]; - OFEnumerator OF_GENERIC(OFZIPArchiveEntry*) *entryEnumerator; - OFZIPArchiveEntry *entry; - bool all; - OFMutableSet OF_GENERIC(OFString*) *missing; - - all = ([files count] == 0); - missing = [OFMutableSet setWithArray: files]; - - entryEnumerator = [[archive entries] objectEnumerator]; - while ((entry = [entryEnumerator nextObject]) != nil) { + bool all = ([files count] == 0); + OFMutableSet OF_GENERIC(OFString*) *missing = + [OFMutableSet setWithArray: files]; + + for (OFZIPArchiveEntry *entry in [archive entries]) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = [entry fileName]; OFString *outFileName = [fileName stringByStandardizingPath]; OFArray OF_GENERIC(OFString*) *pathComponents; - OFEnumerator OF_GENERIC(OFString*) *componentEnumerator; - OFString *component, *directory; + OFString *directory; OFStream *stream; OFFile *output; char buffer[BUFFER_SIZE]; uint64_t written = 0, size = [entry uncompressedSize]; int_fast8_t percent = -1, newPercent; @@ -352,12 +341,11 @@ _exitStatus = 1; goto outer_loop_end; } pathComponents = [outFileName pathComponents]; - componentEnumerator = [pathComponents objectEnumerator]; - while ((component = [componentEnumerator nextObject]) != nil) { + for (OFString *component in pathComponents) { if ([component isEqual: OF_PATH_PARENT_DIRECTORY]) { [of_stderr writeFormat: @"Refusing to extract %@!\n", fileName]; _exitStatus = 1; @@ -478,17 +466,13 @@ outer_loop_end: objc_autoreleasePoolPop(pool); } if ([missing count] > 0) { - OFEnumerator OF_GENERIC(OFString*) *enumerator; - OFString *file; - - enumerator = [missing objectEnumerator]; - while ((file = [enumerator nextObject]) != nil) + for (OFString *file in missing) [of_stderr writeFormat: @"File %@ is not in the archive!\n", file]; _exitStatus = 1; } } @end