Index: src/OFApplication.h ================================================================== --- src/OFApplication.h +++ src/OFApplication.h @@ -57,13 +57,13 @@ int *argc; char ***argv; } #ifdef OF_HAVE_PROPERTIES -@property (readonly, retain) OFString *programName; -@property (readonly, retain) OFArray *arguments; -@property (readonly, retain) OFDictionary *environment; +@property (readonly, copy) OFString *programName; +@property (readonly, copy) OFArray *arguments; +@property (readonly, copy) OFDictionary *environment; @property (retain) id delegate; #endif /** * \return The only OFApplication instance in the application Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -130,10 +130,18 @@ forKey: key]; [pool releaseObjects]; } [pool release]; + + /* + * Class swizzle the environment to be immutable, as we don't + * need to change it anymore and expose it only as + * OFDictionary*. But not swizzling it would create a real copy + * each time -[copy] is called. + */ + environment->isa = [OFDictionary class]; } @catch (id e) { [self release]; @throw e; } @@ -156,10 +164,17 @@ arguments = [[OFMutableArray alloc] init]; for (i = 1; i < *argc; i++) [arguments addObject: [OFString stringWithCString: (*argv)[i]]]; + /* + * Class swizzle the arguments to be immutable, as we don't need to + * change them anymore and expose them only as OFArray*. But not + * swizzling it would create a real copy each time -[copy] is called. + */ + arguments->isa = [OFArray class]; + [pool release]; } - (void)getArgumentCount: (int**)argc_ andArgumentValues: (char****)argv_ @@ -168,21 +183,21 @@ *argv_ = argv; } - (OFString*)programName { - return [[programName retain] autorelease]; + return [[programName copy] autorelease]; } - (OFArray*)arguments { - return [[arguments retain] autorelease]; + return [[arguments copy] autorelease]; } - (OFDictionary*)environment { - return [[environment retain] autorelease]; + return [[environment copy] autorelease]; } - (id )delegate { return [[(id)delegate retain] autorelease]; Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -334,10 +334,16 @@ } append(str, @selector(appendString:), [objs[i] description]); [pool release]; + /* + * Class swizzle the string to be immutable. We declared the return type + * to be OFString*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + str->isa = [OFString class]; return str; } - (BOOL)isEqual: (id)obj { @@ -399,11 +405,19 @@ [ret release]; } [pool release]; - return [ret autorelease]; + [ret autorelease]; + + /* + * Class swizzle the string to be immutable. We declared the return type + * to be OFString*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFString class]; + return ret; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count_ Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -618,10 +618,16 @@ for (i = 0; i < size; i++) if (data[i] != NULL && data[i] != DELETED) [dict setObject: block(data[i]->key, data[i]->object) forKey: data[i]->key]; + /* + * Class swizzle the dictionary to be immutable. We declared the return + * type to be OFDictionary*, so it can't be modified anyway. But not + * swizzling it would create a real copy each time -[copy] is called. + */ + dict->isa = [OFDictionary class]; return dict; } - (OFDictionary*)filteredDictionaryUsingBlock: (of_dictionary_filter_block_t)block @@ -633,10 +639,16 @@ if (data[i] != NULL && data[i] != DELETED) if (block(data[i]->key, data[i]->object)) [dict setObject: data[i]->object forKey: data[i]->key]; + /* + * Class swizzle the dictionary to be immutable. We declared the return + * type to be OFDictionary*, so it can't be modified anyway. But not + * swizzling it would create a real copy each time -[copy] is called. + */ + dict->isa = [OFDictionary class]; return dict; } #endif - (void)dealloc @@ -704,10 +716,16 @@ } [ret appendString: @"}"]; [pool release]; + /* + * Class swizzle the string to be immutable. We declared the return type + * to be OFString*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFString class]; return ret; } @end @implementation OFDictionaryEnumerator Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -200,10 +200,16 @@ [ret addObject: [OFString stringWithCString: path_c + last length: i - last]]; [pool release]; + /* + * Class swizzle the array to be immutable. We declared the return type + * to be OFArray*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFArray class]; return ret; } + (OFString*)lastComponentOfPath: (OFString*)path { @@ -386,10 +392,16 @@ } @finally { FindClose(handle); } #endif + /* + * Class swizzle the array to be immutable. We declared the return type + * to be OFArray*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + files->isa = [OFArray class]; return files; } + (void)changeToDirectory: (OFString*)path { Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -279,10 +279,18 @@ if (cl != [data count]) @throw [OFTruncatedDataException newWithClass: isa]; } + /* + * Class swizzle the dictionary to be immutable. We pass it as + * OFDictionary*, so it can't be modified anyway. But not + * swizzling it would create a real copy each time -[copy] is + * called. + */ + s_headers->isa = [OFDictionary class]; + result = [[OFHTTPRequestResult alloc] initWithStatusCode: status headers: s_headers data: data]; } @finally { Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -311,10 +311,16 @@ [ret appendString: @"]"]; [pool release]; + /* + * Class swizzle the string to be immutable. We declared the return type + * to be OFString*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFString class]; return ret; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects Index: src/OFString+XMLUnescaping.m ================================================================== --- src/OFString+XMLUnescaping.m +++ src/OFString+XMLUnescaping.m @@ -160,10 +160,16 @@ @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; + /* + * Class swizzle the string to be immutable. We declared the return type + * to be OFString*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFString class]; return ret; } #ifdef OF_HAVE_BLOCKS - (OFString*)stringByXMLUnescapingWithBlock: @@ -244,9 +250,15 @@ @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; + /* + * Class swizzle the string to be immutable. We declared the return type + * to be OFString*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFString class]; return ret; } #endif @end Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -999,10 +999,16 @@ OFMutableString *new; new = [OFMutableString stringWithString: self]; [new appendString: str]; + /* + * Class swizzle the string to be immutable. We declared the return type + * to be OFString*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + new->isa = [OFString class]; return new; } - (BOOL)hasPrefix: (OFString*)prefix { @@ -1054,10 +1060,16 @@ } [array addObject: [OFString stringWithCString: string + last]]; [pool release]; + /* + * Class swizzle the array to be immutable. We declared the return type + * to be OFArray*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + array->isa = [OFArray class]; return array; } - (intmax_t)decimalValue { Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -515,8 +515,14 @@ [desc appendFormat: @"?%@", query]; if (fragment != nil) [desc appendFormat: @"#%@", fragment]; + /* + * Class swizzle the string to be immutable. We declared the return type + * to be OFString*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + desc->isa = [OFString class]; return desc; } @end Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -218,10 +218,17 @@ str = [OFMutableString stringWithString: @""]; + /* + * Class swizzle the string to be immutable. We declared the + * return type to be OFString*, so it can't be modified anyway. + * But not swizzling it would create a real copy each time + * -[copy] is called. + */ + str->isa = [OFString class]; return str; } pool = [[OFAutoreleasePool alloc] init]; def_ns = (defaultNamespace != nil Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -354,10 +354,17 @@ len = [pi length]; [pi removeCharactersFromIndex: len - 1 toIndex: len]; + /* + * Class swizzle the string to be immutable. We pass it as + * OFString*, so it can't be modified anyway. But not swizzling + * it would create a real copy each time -[copy] is called. + */ + pi->isa = [OFString class]; + [delegate parser: self foundProcessingInstructions: pi]; [pool release]; @@ -808,10 +815,17 @@ len = [cdata length]; [cdata removeCharactersFromIndex: len - 2 toIndex: len]; + /* + * Class swizzle the string to be immutable. We pass it as OFString*, so + * it can't be modified anyway. But not swizzling it would create a + * real copy each time -[copy] is called. + */ + cdata->isa = [OFString class]; + #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) if (CDATAHandler != NULL) CDATAHandler(self, cdata); else #endif @@ -871,10 +885,17 @@ len = [comment length]; [comment removeCharactersFromIndex: len - 2 toIndex: len]; + /* + * Class swizzle the string to be immutable. We pass it as OFString*, so + * it can't be modified anyway. But not swizzling it would create a + * real copy each time -[copy] is called. + */ + comment->isa = [OFString class]; + #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) if (commentHandler != NULL) commentHandler(self, comment); else #endif Index: src/base64.m ================================================================== --- src/base64.m +++ src/base64.m @@ -85,10 +85,16 @@ length: 4]; break; } + /* + * Class swizzle the string to be immutable. We declared the return type + * to be OFString*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFString class]; return ret; } BOOL of_base64_decode(OFDataArray *data, const char *str, size_t len)