aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-10-16 02:07:20 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-11-19 03:31:47 +0100
commit2562d108fab3ab2585394cc7da77edb50ee142d9 (patch)
tree701c6594541fbbd7557e6704187a48be19e61421
parentda3a4842f11684dfafa15b347717b845a4ba82c3 (diff)
downloadtdv-2562d108fab3ab2585394cc7da77edb50ee142d9.tar.gz
tdv-2562d108fab3ab2585394cc7da77edb50ee142d9.tar.xz
tdv-2562d108fab3ab2585394cc7da77edb50ee142d9.zip
Avoid some overhead with iconv()
Now, in theory, terminal output could actually be a bit faster.
-rw-r--r--src/sdtui.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/sdtui.c b/src/sdtui.c
index 4834b56..f607cc9 100644
--- a/src/sdtui.c
+++ b/src/sdtui.c
@@ -74,6 +74,7 @@ struct application
termo_t * tk; //!< termo handle
guint tk_timeout; //!< termo timeout
GIConv ucs4_to_locale; //!< UTF-32 -> locale conversion
+ gboolean locale_is_utf8; //!< The locale is Unicode
StardictDict * dict; //!< The current dictionary
guint show_help : 1; //!< Whether help can be shown
@@ -222,7 +223,7 @@ app_init (Application *self, const gchar *filename)
self->division = 0.5;
const char *charset;
- (void) g_get_charset (&charset);
+ self->locale_is_utf8 = g_get_charset (&charset);
self->ucs4_to_locale = g_iconv_open (charset, "UTF-32");
app_reload_view (self);
@@ -250,6 +251,10 @@ app_destroy (Application *self)
static gboolean
app_is_character_in_locale (Application *self, gunichar ch)
{
+ // Avoid the overhead joined with calling iconv() for all characters
+ if (self->locale_is_utf8)
+ return TRUE;
+
gchar *tmp = g_convert_with_iconv ((const gchar *) &ch, sizeof ch,
self->ucs4_to_locale, NULL, NULL, NULL);
if (!tmp)