diff --git a/ChangeLog b/ChangeLog index f8b928b3c..716b19fcc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Nov 03 08:35:00 2003 Richard Frith-Macdonald + + * Source/GSString.m: Remove unnecessary -copy implementations for + simplicity, and add code to avoid creating substrings of strings + which do not own their buffers ... stopgap until Alexander + reorganises class hierarchy. + 2003-11-02 01:53 Alexander Malmberg * Source/GSString.m ([GSCSubString -copy]): Add as a stopgap diff --git a/Source/GSString.m b/Source/GSString.m index cc8cc4c78..109f99085 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -1687,36 +1687,55 @@ rangeOfString_u(ivars self, NSString *aString, unsigned mask, NSRange aRange) static inline NSString* substring_c(ivars self, NSRange aRange) { - GSCSubString *sub; + id sub; - sub = (GSCSubString*)NSAllocateObject(GSCSubStringClass, 0, - NSDefaultMallocZone()); - sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location - length: aRange.length - freeWhenDone: NO]; - if (sub != nil) + if (self->_flags.free == 1) { - sub->_parent = RETAIN((id)self); - AUTORELEASE(sub); + sub = NSAllocateObject(GSCSubStringClass, 0, NSDefaultMallocZone()); + sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location + length: aRange.length + freeWhenDone: NO]; + if (sub != nil) + { + ((GSCSubString*)sub)->_parent = RETAIN((id)self); + } } + else + { + sub = NSAllocateObject(GSCInlineStringClass, + aRange.length, NSDefaultMallocZone()); + sub = [sub initWithCString: self->_contents.c + aRange.location + length: aRange.length]; + } + AUTORELEASE(sub); return sub; } static inline NSString* substring_u(ivars self, NSRange aRange) { - GSUnicodeSubString *sub; + id sub; - sub = (GSUnicodeSubString*)NSAllocateObject(GSUnicodeSubStringClass, 0, - NSDefaultMallocZone()); - sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location - length: aRange.length - freeWhenDone: NO]; - if (sub != nil) + if (self->_flags.free == 1) { - sub->_parent = RETAIN((id)self); - AUTORELEASE(sub); + sub = NSAllocateObject(GSUnicodeSubStringClass, 0, NSDefaultMallocZone()); + sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location + length: aRange.length + freeWhenDone: NO]; + if (sub != nil) + { + ((GSUnicodeSubString*)sub)->_parent = RETAIN((id)self); + } } + else + { + sub = NSAllocateObject(GSUnicodeInlineStringClass, + aRange.length*sizeof(unichar), + NSDefaultMallocZone()); + sub = [sub initWithCharacters: self->_contents.u + aRange.location + length: aRange.length]; + } + AUTORELEASE(sub); return sub; } @@ -1953,30 +1972,6 @@ transmute(ivars self, NSString *aString) return compare_c((ivars)self, aString, mask, aRange); } -- (id) copy -{ - if (_flags.free == NO - || NSShouldRetainWithZone(self, NSDefaultMallocZone()) == NO) - { - GSCString *obj; - - obj = (GSCString*)NSCopyObject(self, 0, NSDefaultMallocZone()); - if (_contents.c != 0) - { - unsigned char *tmp; - - tmp = NSZoneMalloc(NSDefaultMallocZone(), _count); - memcpy(tmp, _contents.c, _count); - obj->_contents.c = tmp; - } - return obj; - } - else - { - return RETAIN(self); - } -} - - (id) copyWithZone: (NSZone*)z { if (_flags.free == NO @@ -2197,10 +2192,6 @@ transmute(ivars self, NSString *aString) _flags.wide = 0; return self; } -- (id) copy -{ - return RETAIN(self); -} - (id) copyWithZone: (NSZone*)z { if (NSShouldRetainWithZone(self, z) == NO) @@ -2232,10 +2223,6 @@ transmute(ivars self, NSString *aString) /* * Assume that a copy should be a new string, never just a retained substring. */ -- (id) copy -{ - return [self copyWithZone: NSDefaultMallocZone()]; -} - (id) copyWithZone: (NSZone*)z { NSString *obj; @@ -2281,30 +2268,6 @@ transmute(ivars self, NSString *aString) return compare_u((ivars)self, aString, mask, aRange); } -- (id) copy -{ - if (_flags.free == NO - || NSShouldRetainWithZone(self, NSDefaultMallocZone()) == NO) - { - GSUnicodeString *obj; - - obj = (GSUnicodeString*)NSCopyObject(self, 0, NSDefaultMallocZone()); - if (_contents.u != 0) - { - unichar *tmp; - - tmp = NSZoneMalloc(NSDefaultMallocZone(), _count*sizeof(unichar)); - memcpy(tmp, _contents.u, _count*sizeof(unichar)); - obj->_contents.u = tmp; - } - return obj; - } - else - { - return RETAIN(self); - } -} - - (id) copyWithZone: (NSZone*)z { if (_flags.free == NO @@ -2531,10 +2494,6 @@ transmute(ivars self, NSString *aString) _flags.wide = 1; return self; } -- (id) copy -{ - return RETAIN(self); -} - (id) copyWithZone: (NSZone*)z { if (NSShouldRetainWithZone(self, z) == NO) @@ -2710,25 +2669,6 @@ transmute(ivars self, NSString *aString) return compare_c((ivars)self, aString, mask, aRange); } -- (id) copy -{ - id copy; - - if (_flags.wide == 1) - { - copy = NSAllocateObject(GSUnicodeInlineStringClass, - _count*sizeof(unichar), NSDefaultMallocZone()); - copy = [copy initWithCharacters: _contents.u length: _count]; - } - else - { - copy = NSAllocateObject(GSCInlineStringClass, - _count, NSDefaultMallocZone()); - copy = [copy initWithCString: _contents.c length: _count]; - } - return copy; -} - - (id) copyWithZone: (NSZone*)z { id copy; @@ -3413,11 +3353,6 @@ transmute(ivars self, NSString *aString) [super dealloc]; } -- (id) copy -{ - return [_parent copy]; -} - - (id) copyWithZone: (NSZone*)z { return [_parent copyWithZone: z]; @@ -3779,11 +3714,6 @@ transmute(ivars self, NSString *aString) return self; } -- (id) copy -{ - return self; -} - - (id) copyWithZone: (NSZone*)z { return self;