Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -165,17 +165,11 @@ setObject: [OFString stringWithCString: env] forKey: @"USER"]; #endif [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]; + [environment makeImmutable]; } @catch (id e) { [self release]; @throw e; } Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -369,18 +369,14 @@ [pool2 releaseObjects]; } append(ret, @selector(appendString:), [cArray[i] description]); + [ret makeImmutable]; + [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 = [OFString class]; return ret; } - (BOOL)isEqual: (id)object { @@ -449,18 +445,13 @@ @throw e; } [pool release]; + [ret makeImmutable]; [ret autorelease]; - /* - * 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 = [OFString class]; return ret; } - (OFXMLElement*)XMLElementBySerializing { Index: src/OFCountedSet.m ================================================================== --- src/OFCountedSet.m +++ src/OFCountedSet.m @@ -114,18 +114,14 @@ } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)}"]; + [ret makeImmutable]; + [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; } - copy { @@ -246,6 +242,10 @@ [self addObject: object]; } [pool release]; } + +- (void)makeImmutable +{ +} @end Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -750,16 +750,12 @@ BOOL *stop) { [new setObject: block(key, object) forKey: 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. - */ - new->isa = [OFDictionary class]; + [new makeImmutable]; + return new; } - (OFDictionary*)filteredDictionaryUsingBlock: (of_dictionary_filter_block_t)block @@ -771,16 +767,12 @@ if (block(key, object)) [new setObject: object forKey: 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. - */ - new->isa = [OFDictionary class]; + [new makeImmutable]; + return new; } #endif - (void)dealloc @@ -857,18 +849,14 @@ } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @";\n}"]; + [ret makeImmutable]; + [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; } - (OFXMLElement*)XMLElementBySerializing { Index: src/OFDoubleMatrix.m ================================================================== --- src/OFDoubleMatrix.m +++ src/OFDoubleMatrix.m @@ -274,16 +274,12 @@ } } [description appendString: @")>"]; - /* - * 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. - */ - description->isa = [OFString class]; + [description makeImmutable]; + return description; } - (double*)cArray { Index: src/OFDoubleVector.m ================================================================== --- src/OFDoubleVector.m +++ src/OFDoubleVector.m @@ -247,16 +247,12 @@ [description appendFormat: @"%g, ", data[i]]; else [description appendFormat: @"%g)>", data[i]]; } - /* - * 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. - */ - description->isa = [OFString class]; + [description makeImmutable]; + return description; } - (double*)cArray { Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -301,11 +301,13 @@ } [pool release]; #endif - return [files makeImmutable]; + [files makeImmutable]; + + return files; } + (void)changeToDirectory: (OFString*)path { if (chdir([path cString])) Index: src/OFFloatMatrix.m ================================================================== --- src/OFFloatMatrix.m +++ src/OFFloatMatrix.m @@ -274,16 +274,12 @@ } } [description appendString: @")>"]; - /* - * 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. - */ - description->isa = [OFString class]; + [description makeImmutable]; + return description; } - (float*)cArray { Index: src/OFFloatVector.m ================================================================== --- src/OFFloatVector.m +++ src/OFFloatVector.m @@ -247,16 +247,12 @@ [description appendFormat: @"%g, ", data[i]]; else [description appendFormat: @"%g)>", data[i]]; } - /* - * 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. - */ - description->isa = [OFString class]; + [description makeImmutable]; + return description; } - (float*)cArray { Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -396,17 +396,11 @@ status == 301 || status == 302 || status == 303)) @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. - */ - serverHeaders->isa = [OFDictionary class]; + [serverHeaders makeImmutable]; result = [[OFHTTPRequestResult alloc] initWithStatusCode: status headers: serverHeaders data: data]; Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -349,18 +349,14 @@ } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n]"]; + [ret makeImmutable]; + [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; } - (OFXMLElement*)XMLElementBySerializing { Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -120,10 +120,10 @@ #endif /** * \brief Converts the mutable array to an immutable array. */ -- (OFArray*)makeImmutable; +- (void)makeImmutable; @end @interface OFMutableArrayPlaceholder: OFMutableArray @end Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -238,10 +238,9 @@ withObject: block(object, index, stop)]; }]; } #endif -- (OFArray*)makeImmutable +- (void)makeImmutable { - return self; } @end Index: src/OFMutableCArray.m ================================================================== --- src/OFMutableCArray.m +++ src/OFMutableCArray.m @@ -270,11 +270,10 @@ cArray[i] = newObject; } } #endif -- (OFArray*)makeImmutable +- (void)makeImmutable { isa = [OFCArray class]; - return self; } @end Index: src/OFMutableDictionary.h ================================================================== --- src/OFMutableDictionary.h +++ src/OFMutableDictionary.h @@ -58,6 +58,11 @@ #if defined(OF_SET_M) || defined(OF_MUTABLE_SET_M) || defined(OF_COUNTED_SET_M) - (void)_setObject: (id)object forKey: (id)key copyKey: (BOOL)copyKey; #endif + +/** + * \brief Converts the mutable dictionary to an immutable dictionary. + */ +- (void)makeImmutable; @end Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -319,6 +319,11 @@ data[i]->object = new; } } } #endif + +- (void)makeImmutable +{ + isa = [OFDictionary class]; +} @end Index: src/OFMutableSet.h ================================================================== --- src/OFMutableSet.h +++ src/OFMutableSet.h @@ -57,6 +57,11 @@ * \brief Creates a union of the receiver and the specified set. * * \param set The set to create the union with */ - (void)unionSet: (OFSet*)set; + +/** + * \brief Converts the mutable set to an immutable set. + */ +- (void)makeImmutable; @end Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -77,6 +77,11 @@ while ((object = [enumerator nextObject]) != nil) [self addObject: object]; [pool release]; } + +- (void)makeImmutable +{ + isa = [OFSet class]; +} @end Index: src/OFMutableString.h ================================================================== --- src/OFMutableString.h +++ src/OFMutableString.h @@ -156,6 +156,11 @@ /** * \brief Deletes all whitespaces at the beginning and the end of the string. */ - (void)deleteEnclosingWhitespaces; + +/** + * \brief Converts the mutable string to an immutable string. + */ +- (void)makeImmutable; @end Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -657,6 +657,11 @@ - copy { return [[OFString alloc] initWithString: self]; } + +- (void)makeImmutable +{ + isa = [OFString class]; +} @end Index: src/OFSet.m ================================================================== --- src/OFSet.m +++ src/OFSet.m @@ -213,18 +213,14 @@ } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)}"]; + [ret makeImmutable]; + [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; } - copy { @@ -313,15 +309,11 @@ BOOL *stop) { if (block(key)) [ret addObject: key]; }]; - /* - * Class swizzle the set to be immutable. We declared the return type - * to be OFSet*, so it can't be modified anyway. But not swizzling it - * would create a real copy each time -[copy] is called. - */ - ret->isa = [OFSet class]; + [ret makeImmutable]; + return ret; } #endif @end Index: src/OFString+XMLUnescaping.m ================================================================== --- src/OFString+XMLUnescaping.m +++ src/OFString+XMLUnescaping.m @@ -169,16 +169,12 @@ @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendCString: string + last withLength: 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]; + [ret makeImmutable]; + return ret; } #ifdef OF_HAVE_BLOCKS - (OFString*)stringByXMLUnescapingWithBlock: @@ -267,15 +263,11 @@ @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendCString: string + last withLength: 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]; + [ret makeImmutable]; + return ret; } #endif @end Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1422,106 +1422,78 @@ OFMutableString *new; new = [OFMutableString stringWithString: self]; [new appendString: string]; - /* - * 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]; + [new makeImmutable]; + return new; } - (OFString*)stringByPrependingString: (OFString*)string { OFMutableString *new = [[string mutableCopy] autorelease]; [new appendString: self]; - /* - * 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]; + [new makeImmutable]; + return new; } - (OFString*)uppercaseString { OFMutableString *new = [[self mutableCopy] autorelease]; [new upper]; - /* - * 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]; + [new makeImmutable]; + return new; } - (OFString*)lowercaseString { OFMutableString *new = [[self mutableCopy] autorelease]; [new lower]; - /* - * 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]; + [new makeImmutable]; + return new; } - (OFString*)stringByDeletingLeadingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteLeadingWhitespaces]; - /* - * 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]; + [new makeImmutable]; + return new; } - (OFString*)stringByDeletingTrailingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteTrailingWhitespaces]; - /* - * 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]; + [new makeImmutable]; + return new; } - (OFString*)stringByDeletingEnclosingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteEnclosingWhitespaces]; - /* - * 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]; + [new makeImmutable]; + return new; } - (BOOL)hasPrefix: (OFString*)prefix { @@ -1571,13 +1543,15 @@ i += cStringLength - 1; last = i + 1; } [array addObject: [OFString stringWithCString: s->cString + last]]; + [array makeImmutable]; + [pool release]; - return [array makeImmutable]; + return array; } - (OFArray*)pathComponents { OFMutableArray *ret; @@ -1613,13 +1587,15 @@ } [ret addObject: [OFString stringWithCString: s->cString + last length: i - last]]; + [ret makeImmutable]; + [pool release]; - return [ret makeImmutable]; + return ret; } - (OFString*)lastPathComponent { size_t pathCStringLength = s->cStringLength; Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -530,16 +530,12 @@ [ret appendFormat: @"?%@", query]; if (fragment != nil) [ret 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. - */ - ret->isa = [OFString class]; + [ret makeImmutable]; + return ret; } - (OFString*)description { Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -458,18 +458,14 @@ [ret appendString: [cArray[i] stringValue]]; [pool releaseObjects]; } } + [ret makeImmutable]; + [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; } - (intmax_t)decimalValue { @@ -1034,11 +1030,13 @@ for (i = 0; i < count; i++) if (cArray[i]->name != nil) [ret addObject: cArray[i]]; - return [ret makeImmutable]; + [ret makeImmutable]; + + return ret; } - (OFArray*)elementsForName: (OFString*)elementName { OFMutableArray *ret = [OFMutableArray array]; @@ -1048,11 +1046,13 @@ for (i = 0; i < count; i++) if (cArray[i]->ns == nil && [cArray[i]->name isEqual: elementName]) [ret addObject: cArray[i]]; - return [ret makeImmutable]; + [ret makeImmutable]; + + return ret; } - (OFArray*)elementsForNamespace: (OFString*)elementNS { OFMutableArray *ret = [OFMutableArray array]; @@ -1062,11 +1062,13 @@ for (i = 0; i < count; i++) if (cArray[i]->name != nil && [cArray[i]->ns isEqual: elementNS]) [ret addObject: cArray[i]]; - return [ret makeImmutable]; + [ret makeImmutable]; + + return ret; } - (OFArray*)elementsForName: (OFString*)elementName namespace: (OFString*)elementNS { @@ -1084,11 +1086,13 @@ for (i = 0; i < count; i++) if ([cArray[i]->ns isEqual: elementNS] && [cArray[i]->name isEqual: elementName]) [ret addObject: cArray[i]]; - return [ret makeImmutable]; + [ret makeImmutable]; + + return ret; } - (BOOL)isEqual: (id)object { OFXMLElement *otherElement; Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -80,11 +80,12 @@ } if (unescape) return [ret stringByXMLUnescapingWithDelegate: delegate]; - ret->isa = [OFString class]; + [ret makeImmutable]; + return ret; } static OFString* namespace_for_prefix(OFString *prefix, OFArray *namespaces) @@ -792,11 +793,11 @@ cacheString = [OFMutableString stringWithCString: [cache cArray] length: [cache count]]; [cacheString deleteEnclosingWhitespaces]; /* Prevent a useless copy later */ - cacheString->isa = [OFString class]; + [cacheString makeImmutable]; cacheCString = [cacheString cString]; cacheLength = [cacheString cStringLength]; if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) { Index: src/base64.m ================================================================== --- src/base64.m +++ src/base64.m @@ -85,16 +85,12 @@ withLength: 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]; + [ret makeImmutable]; + return ret; } BOOL of_base64_decode(OFDataArray *data, const char *string, size_t length)