From 21abb5113086a3d806c8d1a636227bec47e57fc8 Mon Sep 17 00:00:00 2001 From: Emanuele Giaquinta Date: Tue, 10 Jun 2008 22:49:00 +0000 Subject: 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 --- src/core/recode.c | 44 ++++++++++++++++++------------------------ src/core/recode.h | 1 + src/fe-common/core/fe-recode.c | 1 + 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/core/recode.c b/src/core/recode.c index 5a7c9aef..5e68cea8 100644 --- a/src/core/recode.c +++ b/src/core/recode.c @@ -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); } diff --git a/src/core/recode.h b/src/core/recode.h index 9698ae2f..c8f867cf 100644 --- a/src/core/recode.h +++ b/src/core/recode.h @@ -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); diff --git a/src/fe-common/core/fe-recode.c b/src/fe-common/core/fe-recode.c index f0ce6da9..dbc43574 100644 --- a/src/fe-common/core/fe-recode.c +++ b/src/fe-common/core/fe-recode.c @@ -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); -- cgit v1.2.3