Only get default locale at the point when it's actually needed

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39651 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2016-04-08 17:28:05 +00:00
parent f306de43e8
commit a577d2d316

View file

@ -84,6 +84,8 @@ static NSString* (*abrIMP)(id, SEL, id);
static NSString* (*absAbrIMP)(id, SEL, id); static NSString* (*absAbrIMP)(id, SEL, id);
static NSString* (*dstAbrIMP)(id, SEL, id); static NSString* (*dstAbrIMP)(id, SEL, id);
#define LOCALE (nil == locale ? (locale = GSPrivateDefaultLocale()) : locale)
/* /*
* Return the offset from GMT for a date in a timezone ... * Return the offset from GMT for a date in a timezone ...
@ -732,13 +734,9 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
} }
source = [description cString]; source = [description cString];
sourceLen = strlen(source); sourceLen = strlen(source);
if (locale == nil)
{
locale = GSPrivateDefaultLocale();
}
if (fmt == nil) if (fmt == nil)
{ {
fmt = [locale objectForKey: NSTimeDateFormatString]; fmt = [LOCALE objectForKey: NSTimeDateFormatString];
if (fmt == nil) if (fmt == nil)
{ {
fmt = @""; fmt = @"";
@ -781,7 +779,7 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
if (c == 'c') if (c == 'c')
{ {
sub = [locale objectForKey: NSTimeDateFormatString]; sub = [LOCALE objectForKey: NSTimeDateFormatString];
if (sub == nil) if (sub == nil)
{ {
sub = @"%X %x"; sub = @"%X %x";
@ -805,7 +803,7 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
} }
else if (c == 'X') else if (c == 'X')
{ {
sub = [locale objectForKey: NSTimeFormatString]; sub = [LOCALE objectForKey: NSTimeFormatString];
if (sub == nil) if (sub == nil)
{ {
sub = @"%H-%M-%S"; sub = @"%H-%M-%S";
@ -813,7 +811,7 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
} }
else if (c == 'x') else if (c == 'x')
{ {
sub = [locale objectForKey: NSShortDateFormatString]; sub = [LOCALE objectForKey: NSShortDateFormatString];
if (sub == nil) if (sub == nil)
{ {
sub = @"%y-%m-%d"; sub = @"%y-%m-%d";
@ -955,7 +953,7 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
NSArray *dayNames; NSArray *dayNames;
currDay = [[NSString alloc] initWithCString: tmpStr]; currDay = [[NSString alloc] initWithCString: tmpStr];
dayNames = [locale objectForKey: NSShortWeekDayNameArray]; dayNames = [LOCALE objectForKey: NSShortWeekDayNameArray];
for (tmpIdx = 0; tmpIdx < 7; tmpIdx++) for (tmpIdx = 0; tmpIdx < 7; tmpIdx++)
{ {
if ([[dayNames objectAtIndex: tmpIdx] isEqual: if ([[dayNames objectAtIndex: tmpIdx] isEqual:
@ -1007,7 +1005,7 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
NSArray *dayNames; NSArray *dayNames;
currDay = [[NSString alloc] initWithCString: tmpStr]; currDay = [[NSString alloc] initWithCString: tmpStr];
dayNames = [locale objectForKey: NSWeekDayNameArray]; dayNames = [LOCALE objectForKey: NSWeekDayNameArray];
for (tmpIdx = 0; tmpIdx < 7; tmpIdx++) for (tmpIdx = 0; tmpIdx < 7; tmpIdx++)
{ {
if ([[dayNames objectAtIndex: tmpIdx] isEqual: if ([[dayNames objectAtIndex: tmpIdx] isEqual:
@ -1051,7 +1049,7 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
NSArray *monthNames; NSArray *monthNames;
currMonth = [[NSString alloc] initWithCString: tmpStr]; currMonth = [[NSString alloc] initWithCString: tmpStr];
monthNames = [locale objectForKey: NSShortMonthNameArray]; monthNames = [LOCALE objectForKey: NSShortMonthNameArray];
for (tmpIdx = 0; tmpIdx < 12; tmpIdx++) for (tmpIdx = 0; tmpIdx < 12; tmpIdx++)
{ {
@ -1104,7 +1102,7 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
NSArray *monthNames; NSArray *monthNames;
currMonth = [[NSString alloc] initWithCString: tmpStr]; currMonth = [[NSString alloc] initWithCString: tmpStr];
monthNames = [locale objectForKey: NSMonthNameArray]; monthNames = [LOCALE objectForKey: NSMonthNameArray];
for (tmpIdx = 0; tmpIdx < 12; tmpIdx++) for (tmpIdx = 0; tmpIdx < 12; tmpIdx++)
{ {
@ -1210,7 +1208,7 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
NSArray *amPMNames; NSArray *amPMNames;
currAMPM = [NSString stringWithUTF8String: tmpStr]; currAMPM = [NSString stringWithUTF8String: tmpStr];
amPMNames = [locale objectForKey: NSAMPMDesignation]; amPMNames = [LOCALE objectForKey: NSAMPMDesignation];
/* /*
* The time addition is handled below because this * The time addition is handled below because this
@ -1994,24 +1992,24 @@ static void outputValueWithFormat(int v, char *fldfmt, DescriptionInfo *info)
break; break;
case 'c': case 'c':
[self _format: [locale objectForKey: NSTimeFormatString] [self _format: [LOCALE objectForKey: NSTimeFormatString]
locale: locale locale: locale
info: info]; info: info];
Grow(info, 1); Grow(info, 1);
info->t[info->offset++] = ' '; info->t[info->offset++] = ' ';
[self _format: [locale objectForKey: NSDateFormatString] [self _format: [LOCALE objectForKey: NSDateFormatString]
locale: locale locale: locale
info: info]; info: info];
break; break;
case 'X': case 'X':
[self _format: [locale objectForKey: NSTimeFormatString] [self _format: [LOCALE objectForKey: NSTimeFormatString]
locale: locale locale: locale
info: info]; info: info];
break; break;
case 'x': case 'x':
[self _format: [locale objectForKey: NSDateFormatString] [self _format: [LOCALE objectForKey: NSDateFormatString]
locale: locale locale: locale
info: info]; info: info];
break; break;
@ -2057,9 +2055,9 @@ static void outputValueWithFormat(int v, char *fldfmt, DescriptionInfo *info)
NSArray *months; NSArray *months;
if (mname) if (mname)
months = [locale objectForKey: NSShortMonthNameArray]; months = [LOCALE objectForKey: NSShortMonthNameArray];
else else
months = [locale objectForKey: NSMonthNameArray]; months = [LOCALE objectForKey: NSMonthNameArray];
if (info->md > [months count]) if (info->md > [months count])
{ {
mtag = NO; mtag = NO;
@ -2153,9 +2151,9 @@ static void outputValueWithFormat(int v, char *fldfmt, DescriptionInfo *info)
NSArray *days; NSArray *days;
if (dname) if (dname)
days = [locale objectForKey: NSShortWeekDayNameArray]; days = [LOCALE objectForKey: NSShortWeekDayNameArray];
else else
days = [locale objectForKey: NSWeekDayNameArray]; days = [LOCALE objectForKey: NSWeekDayNameArray];
if (v < [days count]) if (v < [days count])
{ {
NSString *name; NSString *name;
@ -2258,7 +2256,7 @@ static void outputValueWithFormat(int v, char *fldfmt, DescriptionInfo *info)
// Is it the am/pm indicator // Is it the am/pm indicator
case 'p': case 'p':
{ {
NSArray *a = [locale objectForKey: NSAMPMDesignation]; NSArray *a = [LOCALE objectForKey: NSAMPMDesignation];
NSString *ampm; NSString *ampm;
if (info->hd >= 12) if (info->hd >= 12)
@ -2440,10 +2438,8 @@ static void outputValueWithFormat(int v, char *fldfmt, DescriptionInfo *info)
NSString *result; NSString *result;
DescriptionInfo info; DescriptionInfo info;
if (locale == nil)
locale = GSPrivateDefaultLocale();
if (format == nil) if (format == nil)
format = [locale objectForKey: NSTimeDateFormatString]; format = [LOCALE objectForKey: NSTimeDateFormatString];
GSBreakTime(_seconds_since_ref + offset(_time_zone, self), GSBreakTime(_seconds_since_ref + offset(_time_zone, self),
&info.yd, &info.md, &info.dom, &info.hd, &info.mnd, &info.sd, &info.mil); &info.yd, &info.md, &info.dom, &info.hd, &info.mnd, &info.sd, &info.mil);