Skip to content

Commit

Permalink
Fix for issue 459
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Nov 8, 2024
1 parent 82bd121 commit 9df544f
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions Source/NSString.m
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ - (instancetype) initWithMask: (NSUInteger) aMask locale: (NSLocale *) aLocale
return self;
}

- (void) dealloc {
- (void) dealloc
{
RELEASE(locale);
if (collator != NULL)
{
Expand All @@ -630,33 +631,37 @@ - (void) _setStringCollatorCache: (id)cache;
static UCollator *
GSICUCachedCollator(NSStringCompareOptions mask, NSLocale *locale)
{
NSThread *current;
GSICUCollatorCache *cache;
NSThread *current;
GSICUCollatorCache *cache;

current = [NSThread currentThread];
cache = [current _stringCollatorCache];
if (nil == cache) {
cache = [[GSICUCollatorCache alloc] initWithMask: mask locale: locale];
[current _setStringCollatorCache: cache];
[cache release];
return cache->collator;
}
if (nil == cache)
{
cache = [[GSICUCollatorCache alloc] initWithMask: mask locale: locale];
[current _setStringCollatorCache: cache];
[cache release];
return cache->collator;
}

// Do a pointer comparison first to avoid the overhead of isEqual:
// The locale instance is likely a global constant object.
// If this fails, do a full comparison.
if ((cache->locale == locale || [cache->locale isEqual: locale]) && mask == cache->mask)
/* Do a pointer comparison first to avoid the overhead of isEqual:
* The locale instance is likely a global constant object.
* If this fails, do a full comparison.
*/
if ((cache->locale == locale || [cache->locale isEqual: locale])
&& mask == cache->mask)
{
return cache->collator;
}
else
{
{
cache = [[GSICUCollatorCache alloc] initWithMask: mask locale: locale];
[current _setStringCollatorCache: cache];
[cache release];
return cache->collator;
}
}
}
#endif // GS_USE_ICU


@implementation NSString
Expand Down Expand Up @@ -772,7 +777,7 @@ @implementation NSString
0))
#else
arginfo_func))
#endif
#endif // PRINTF_ATSIGN_VA_LIST
[NSException raise: NSGenericException
format: @"register printf handling of %%@ failed"];
#elif defined(HAVE_REGISTER_PRINTF_FUNCTION)
Expand All @@ -781,10 +786,10 @@ @implementation NSString
0))
#else
arginfo_func))
#endif
#endif // PRINTF_ATSIGN_VA_LIST
[NSException raise: NSGenericException
format: @"register printf handling of %%@ failed"];
#endif
#endif // defined(HAVE_REGISTER_PRINTF_FUNCTION)
}


Expand Down Expand Up @@ -872,7 +877,6 @@ - (NSString *) _normalizedICUStringOfType: (const char*)normalization
return AUTORELEASE(newString);
}
#endif
#endif

+ (void) atExit
{
Expand Down Expand Up @@ -6393,14 +6397,12 @@ - (void) enumerateSubstringsInRange: (NSRange)range
uint8_t substringType;
BOOL isReverse;
BOOL substringNotRequired;
BOOL localized;
NSUInteger currentLocation;
BOOL stop = NO;

substringType = opts & 0xFF;
isReverse = opts & NSStringEnumerationReverse;
substringNotRequired = opts & NSStringEnumerationSubstringNotRequired;
localized = opts & NSStringEnumerationLocalized;

if (isReverse)
{
Expand Down Expand Up @@ -6511,7 +6513,7 @@ - (void) enumerateSubstringsInRange: (NSRange)range
/* @ss=standard will use lists of common abbreviations,
* such as Mr., Mrs., etc.
*/
locale = localized
locale = (opts & NSStringEnumerationLocalized)
? [[[[NSLocale currentLocale] localeIdentifier]
stringByAppendingString: @"@ss=standard"] UTF8String]
: "en_US_POSIX";
Expand Down

0 comments on commit 9df544f

Please sign in to comment.