optimize: not even gcc-4.4 would lift strlen out of the loop
This commit is contained in:
parent
d9a5e39118
commit
07abe83e9e
1 changed files with 46 additions and 4 deletions
50
src/i18n.c
50
src/i18n.c
|
|
@ -564,12 +564,51 @@ static const char *language_to_locale(const char *langstr)
|
||||||
show_lang_usage(59);
|
show_lang_usage(59);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_langint_from_locale_string(const char *restrict loc)
|
||||||
|
{
|
||||||
|
if (!loc)
|
||||||
|
return;
|
||||||
|
|
||||||
|
char *baseloc = strdup(loc);
|
||||||
|
|
||||||
|
char *dot = strchr(baseloc, '.');
|
||||||
|
if(dot)
|
||||||
|
*dot = '\0';
|
||||||
|
|
||||||
|
size_t len_baseloc = strlen(baseloc);
|
||||||
|
|
||||||
|
/* Which, if any, of the locales is it? */
|
||||||
|
|
||||||
|
int found = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < NUM_LANGS && found == 0; i++)
|
||||||
|
{
|
||||||
|
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
|
||||||
|
if (len_baseloc == strlen(lang_prefixes[i]) &&
|
||||||
|
!strncasecmp(baseloc, lang_prefixes[i], strlen(lang_prefixes[i])))
|
||||||
|
{
|
||||||
|
langint = i;
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < NUM_LANGS && found == 0; i++)
|
||||||
|
{
|
||||||
|
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
|
||||||
|
if (!strncasecmp(loc, lang_prefixes[i], strlen(lang_prefixes[i])))
|
||||||
|
{
|
||||||
|
langint = i;
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int set_current_language(void) MUST_CHECK;
|
static int set_current_language(void) MUST_CHECK;
|
||||||
static int set_current_language(void)
|
static int set_current_language(void)
|
||||||
{
|
{
|
||||||
char *loc, *baseloc;
|
char *loc;
|
||||||
int i, found;
|
int i;
|
||||||
int y_nudge = 0;
|
int y_nudge = 0;
|
||||||
|
|
||||||
bindtextdomain("tuxpaint", LOCALEDIR);
|
bindtextdomain("tuxpaint", LOCALEDIR);
|
||||||
|
|
@ -601,14 +640,15 @@ static int set_current_language(void)
|
||||||
|
|
||||||
if (loc)
|
if (loc)
|
||||||
{
|
{
|
||||||
baseloc = strdup(loc);
|
char *baseloc = strdup(loc);
|
||||||
|
|
||||||
char *dot = strchr(baseloc, '.');
|
char *dot = strchr(baseloc, '.');
|
||||||
if(dot)
|
if(dot)
|
||||||
*dot = '\0';
|
*dot = '\0';
|
||||||
|
|
||||||
/* Which, if any, of the locales is it? */
|
/* Which, if any, of the locales is it? */
|
||||||
|
|
||||||
found = 0;
|
int found = 0;
|
||||||
|
|
||||||
for (i = 0; i < NUM_LANGS && found == 0; i++)
|
for (i = 0; i < NUM_LANGS && found == 0; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -632,6 +672,8 @@ static int set_current_language(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_langint_from_locale_string(loc);
|
||||||
|
|
||||||
lang_prefix = lang_prefixes[langint];
|
lang_prefix = lang_prefixes[langint];
|
||||||
|
|
||||||
short_lang_prefix = strdup(lang_prefix);
|
short_lang_prefix = strdup(lang_prefix);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue