diff options
author | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-07-17 20:13:54 +0000 |
---|---|---|
committer | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-07-17 20:13:54 +0000 |
commit | 8cefe3b40628bed52be330f78925f5b27e410e83 (patch) | |
tree | e3d53dc86fcf82bb93665397f0f8493a67f330aa /epan/print.c | |
parent | 2ee4339b9eac4122a18a360b839bd384d717c0d0 (diff) |
Optimize print_line_text
- fill spaces[] array once
- use fwrite()
svn path=/trunk/; revision=50705
Diffstat (limited to 'epan/print.c')
-rw-r--r-- | epan/print.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/epan/print.c b/epan/print.c index 25f89b1353..76cbf9d9b1 100644 --- a/epan/print.c +++ b/epan/print.c @@ -1103,23 +1103,25 @@ typedef struct { static gboolean print_line_text(print_stream_t *self, int indent, const char *line) { + static char spaces[MAX_INDENT]; + output_text *output = (output_text *)self->data; - char space[MAX_INDENT+1]; - int i; - int num_spaces; + unsigned int num_spaces; + + /* should be space, if NUL -> initialize */ + if (!spaces[0]) { + int i; + + for (i = 0; i < MAX_INDENT; i++) + spaces[i] = ' '; + } /* Prepare the tabs for printing, depending on tree level */ num_spaces = indent * 4; - if (num_spaces > MAX_INDENT) { + if (num_spaces > MAX_INDENT) num_spaces = MAX_INDENT; - } - for (i = 0; i < num_spaces; i++) { - space[i] = ' '; - } - /* The string is NUL-terminated */ - space[num_spaces] = '\0'; - fputs(space, output->fh); + fwrite(spaces, 1, num_spaces, output->fh); fputs(line, output->fh); putc('\n', output->fh); return !ferror(output->fh); |