@@ -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;