aboutsummaryrefslogtreecommitdiffstats
path: root/epan/print_stream.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2016-06-29 16:51:37 -0700
committerGerald Combs <gerald@wireshark.org>2016-06-30 19:21:04 +0000
commitcd1ddf6ef5c794cf135d8b36916dbdc7aae9ca57 (patch)
tree73e644df7cf8b508f5c4f5eb6d9a5e4502c6ead2 /epan/print_stream.c
parent6b152515abf075b84422d344e085891e2b76f41e (diff)
Speed up print_line_text.
isatty adds a small delay, at least on OS X. Call it only when we allocate a stream. Do the same for our codeset check. Change-Id: Id3a20059dbc9cf7d5db16d8d238d038b9de0ebf2 Reviewed-on: https://code.wireshark.org/review/16222 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'epan/print_stream.c')
-rw-r--r--epan/print_stream.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/epan/print_stream.c b/epan/print_stream.c
index 162bedaef3..0bd2846c30 100644
--- a/epan/print_stream.c
+++ b/epan/print_stream.c
@@ -108,13 +108,6 @@ typedef struct {
#define MAX_INDENT 160
-#ifdef _WIN32
-static char *to_codeset = "UTF-16LE";
-#else
-static char *tty_codeset = NULL;
-static char *to_codeset = NULL;
-#endif
-
static gboolean
print_line_text(print_stream_t *self, int indent, const char *line)
{
@@ -141,26 +134,12 @@ print_line_text(print_stream_t *self, int indent, const char *line)
if (ret == num_spaces) {
gchar *tty_out = NULL;
-#ifndef _WIN32
- /* Is there a more reliable way to do this? */
- if (!tty_codeset) {
- const gchar *charset;
- gboolean is_utf8;
-
- is_utf8 = g_get_charset(&charset);
- tty_codeset = g_strdup(charset);
- if (!is_utf8) {
- to_codeset = tty_codeset;
- }
- }
-#endif
-
- if (ws_isatty(ws_fileno(output->fh)) && to_codeset) {
+ if (self->isatty && self->to_codeset) {
/* XXX Allocating a fresh buffer every line probably isn't the
* most efficient way to do this. However, this has the side
* effect of scrubbing invalid output.
*/
- tty_out = g_convert_with_fallback(line, -1, to_codeset, "UTF-8", "?", NULL, NULL, NULL);
+ tty_out = g_convert_with_fallback(line, -1, self->to_codeset, "UTF-8", "?", NULL, NULL, NULL);
}
if (tty_out) {
@@ -214,14 +193,29 @@ print_stream_text_alloc(gboolean to_file, FILE *fh)
{
print_stream_t *stream;
output_text *output;
+#ifndef _WIN32
+ const gchar *charset;
+ gboolean is_utf8;
+#endif
output = (output_text *)g_malloc(sizeof *output);
output->to_file = to_file;
output->fh = fh;
- stream = (print_stream_t *)g_malloc(sizeof (print_stream_t));
+ stream = (print_stream_t *)g_malloc0(sizeof (print_stream_t));
stream->ops = &print_text_ops;
+ stream->isatty = ws_isatty(ws_fileno(fh));
stream->data = output;
+#ifndef _WIN32
+ /* Is there a more reliable way to do this? */
+ is_utf8 = g_get_charset(&charset);
+ if (!is_utf8) {
+ stream->to_codeset = charset;
+ }
+#else
+ stream->to_codeset = "UTF-16LE";
+#endif
+
return stream;
}