Simple fix to check for whitespace characters using strchr since the old

mechanism using characterset bitmap representations was broken by the
change to reduce waste in bintmaps (the code assumed the bitmap was
bigger than it really is).
This commit is contained in:
Richard Frith-Macdonald 2020-06-24 11:35:29 +01:00
parent ba24a18176
commit b7882e3194

View file

@ -164,39 +164,30 @@ static BOOL (*nonBaseImp)(id, SEL, unichar) = 0;
*/ */
#define IMMUTABLE(S) AUTORELEASE([(S) copyWithZone: NSDefaultMallocZone()]) #define IMMUTABLE(S) AUTORELEASE([(S) copyWithZone: NSDefaultMallocZone()])
#define IS_BIT_SET(a,i) ((((a) & (1<<(i)))) > 0) static const char *whitespace = 0;
static NSCharacterSet *nonspace = nil; static NSCharacterSet *nonspace = nil;
static NSData *whitespaceBitmap; #define GS_IS_WHITESPACE(X) strchr(whitespace, X)
static unsigned const char *whitespaceBitmapRep = NULL;
#define GS_IS_WHITESPACE(X) IS_BIT_SET(whitespaceBitmapRep[(X)/8], (X) % 8)
static void setupNonspace(void) static void setupNonspace(void)
{ {
if (nil == nonspace) if (nil == nonspace)
{ {
NSCharacterSet *whitespace; NSCharacterSet *w;
whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet]; w = [NSCharacterSet whitespaceAndNewlineCharacterSet];
nonspace = [[whitespace invertedSet] retain]; nonspace = [[w invertedSet] retain];
} }
} }
static void setupWhitespace(void) static void setupWhitespace(void)
{ {
if (whitespaceBitmapRep == NULL)
{
NSCharacterSet *whitespace;
/* /*
We can not use whitespaceAndNewlineCharacterSet here as this would lead We can not use whitespaceAndNewlineCharacterSet here as this would lead
to a recursion, as this also reads in a property list. to a recursion, as this also reads in a property list.
whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
*/ */
whitespace = [NSCharacterSet characterSetWithCharactersInString: if (0 == whitespace)
@" \t\r\n\f\b"]; {
whitespaceBitmap = RETAIN([whitespace bitmapRepresentation]); whitespace = " \t\r\n\f\b";
whitespaceBitmapRep = [whitespaceBitmap bytes];
} }
} }
@ -3504,7 +3495,7 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
if (len == 0) if (len == 0)
return IMMUTABLE(self); return IMMUTABLE(self);
if (whitespaceBitmapRep == NULL) if (NULL == whitespace)
setupWhitespace(); setupWhitespace();
s = NSZoneMalloc([self zone], sizeof(unichar)*len); s = NSZoneMalloc([self zone], sizeof(unichar)*len);