diff --git a/ChangeLog b/ChangeLog index 67ab80110..da1b8a7bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * Source/Unicode.m: Rationalise so that all conversion operations go through the two new functions. Gets rid of a load of old code. + * Source/GSString.m: ([-replaceCharactersInRange:withString:]) + minor performance enhancement when copying from a 16-bit string + to an 8-bit string. 2002-05-10 Adam Fedor diff --git a/Source/GSString.m b/Source/GSString.m index 43669202d..488dbf091 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -2938,23 +2938,43 @@ transmute(ivars self, NSString *aString) } else { + /* + * As we got here, intEnc == defEnc, so we can use standard + * CString methods to get the characters into our buffer, + * or may even be able to copy from another string directly. + */ if (other == 0) { - unsigned l; - /* - * Since getCString appends a '\0' terminator, we must ask for - * one character less than we actually want, then get the last - * character separately. + * Since getCString appends a '\0' terminator, we must handle + * that problem in copying data into our buffer. Either by + * saving and restoring the character which would be + * overwritten by the nul, or by getting a character less, + * and fetching the last character separately. */ - l = length - 1; - if (l > 0) + if (aRange.location + length < _count) { + unsigned char tmp = _contents.c[aRange.location + length]; + [aString getCString: &_contents.c[aRange.location] - maxLength: l]; + maxLength: length]; + _contents.c[aRange.location + length] = tmp; + } + else + { + unsigned int l = length - 1; + unsigned int size = 1; + unichar u; + unsigned char *dst = &_contents.c[aRange.location + l]; + + if (l > 0) + { + [aString getCString: &_contents.c[aRange.location] + maxLength: l]; + } + u = [aString characterAtIndex: l]; + GSFromUnicode(&dst, &size, &u, 1, intEnc, 0, 0); } - _contents.c[aRange.location + l] - = encode_unitochar([aString characterAtIndex: l], intEnc); } else {