mirror of
https://github.com/irssi/irssi.git
synced 2024-09-01 04:14:16 -04:00
Cache charset related data rather than computing it everytime recode_{in,out}
is called. git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@4862 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
bd63e4c746
commit
21abb51130
@ -25,21 +25,12 @@
|
||||
#include "lib-config/iconfig.h"
|
||||
#include "misc.h"
|
||||
|
||||
static gboolean recode_get_charset(const char **charset)
|
||||
{
|
||||
*charset = settings_get_str("term_charset");
|
||||
if (**charset)
|
||||
/* we use the same test as in src/fe-text/term.c:123 */
|
||||
return (g_ascii_strcasecmp(*charset, "utf-8") == 0);
|
||||
|
||||
return g_get_charset(charset);
|
||||
}
|
||||
static char *translit_charset;
|
||||
static gboolean term_is_utf8;
|
||||
|
||||
gboolean is_utf8(void)
|
||||
{
|
||||
const char *charset;
|
||||
|
||||
return recode_get_charset(&charset);
|
||||
return term_is_utf8;
|
||||
}
|
||||
|
||||
static gboolean is_translit(const char *charset)
|
||||
@ -89,10 +80,9 @@ static char *find_conversion(const SERVER_REC *server, const char *target)
|
||||
char *recode_in(const SERVER_REC *server, const char *str, const char *target)
|
||||
{
|
||||
const char *from = NULL;
|
||||
const char *to = NULL;
|
||||
char *translit_to = NULL;
|
||||
const char *to = translit_charset;
|
||||
char *recoded = NULL;
|
||||
gboolean term_is_utf8, str_is_utf8, translit, recode, autodetect;
|
||||
gboolean str_is_utf8, recode, autodetect;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
@ -113,12 +103,7 @@ char *recode_in(const SERVER_REC *server, const char *str, const char *target)
|
||||
break;
|
||||
}
|
||||
}
|
||||
translit = settings_get_bool("recode_transliterate");
|
||||
autodetect = settings_get_bool("recode_autodetect_utf8");
|
||||
term_is_utf8 = recode_get_charset(&to);
|
||||
|
||||
if (translit && !is_translit(to))
|
||||
to = translit_to = g_strconcat(to, "//TRANSLIT", NULL);
|
||||
|
||||
if (autodetect && str_is_utf8)
|
||||
if (term_is_utf8)
|
||||
@ -149,17 +134,16 @@ char *recode_in(const SERVER_REC *server, const char *str, const char *target)
|
||||
if (!recoded)
|
||||
recoded = g_strdup(str);
|
||||
}
|
||||
g_free(translit_to);
|
||||
return recoded;
|
||||
}
|
||||
|
||||
char *recode_out(const SERVER_REC *server, const char *str, const char *target)
|
||||
{
|
||||
char *recoded = NULL;
|
||||
const char *from = NULL;
|
||||
const char *from = translit_charset;
|
||||
const char *to = NULL;
|
||||
char *translit_to = NULL;
|
||||
gboolean translit, term_is_utf8, recode;
|
||||
gboolean translit, recode;
|
||||
int len;
|
||||
|
||||
if (!str)
|
||||
@ -182,7 +166,6 @@ char *recode_out(const SERVER_REC *server, const char *str, const char *target)
|
||||
if (translit && !is_translit(to))
|
||||
to = translit_to = g_strconcat(to ,"//TRANSLIT", NULL);
|
||||
|
||||
term_is_utf8 = recode_get_charset(&from);
|
||||
recoded = g_convert(str, len, to, from, NULL, NULL, NULL);
|
||||
}
|
||||
g_free(translit_to);
|
||||
@ -192,6 +175,17 @@ char *recode_out(const SERVER_REC *server, const char *str, const char *target)
|
||||
return recoded;
|
||||
}
|
||||
|
||||
void recode_update_charset(void)
|
||||
{
|
||||
const char *charset = settings_get_str("term_charset");
|
||||
term_is_utf8 = !g_ascii_strcasecmp(charset, "UTF-8");
|
||||
g_free(translit_charset);
|
||||
if (settings_get_bool("recode_transliterate") && !is_translit(charset))
|
||||
translit_charset = g_strconcat(charset, "//TRANSLIT", NULL);
|
||||
else
|
||||
translit_charset = g_strdup(charset);
|
||||
}
|
||||
|
||||
void recode_init(void)
|
||||
{
|
||||
settings_add_bool("misc", "recode", TRUE);
|
||||
@ -203,5 +197,5 @@ void recode_init(void)
|
||||
|
||||
void recode_deinit(void)
|
||||
{
|
||||
|
||||
g_free(translit_charset);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ char *recode_in (const SERVER_REC *server, const char *str, const char *target);
|
||||
char *recode_out (const SERVER_REC *server, const char *str, const char *target);
|
||||
gboolean is_valid_charset(const char *charset);
|
||||
gboolean is_utf8(void);
|
||||
void recode_update_charset(void);
|
||||
|
||||
void recode_init (void);
|
||||
void recode_deinit (void);
|
||||
|
@ -172,6 +172,7 @@ static void read_settings(void)
|
||||
term_charset = is_valid_charset(old_term_charset) ? g_strdup(old_term_charset) : NULL;
|
||||
settings_set_str("term_charset", term_charset);
|
||||
}
|
||||
recode_update_charset();
|
||||
|
||||
if (recode_out_default)
|
||||
g_free(recode_out_default);
|
||||
|
Loading…
Reference in New Issue
Block a user