summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-01-17 22:15:48 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-01-17 22:15:48 +0100
commit588a696c685797a2d788ab51f4b85113bd4c5e30 (patch)
tree8bc45481c1c718dbd75cec972fd22262d4ba67db /degesch.c
parent6db40c450399f215b1abdb42d5d1d6dee58debb4 (diff)
downloadxK-588a696c685797a2d788ab51f4b85113bd4c5e30.tar.gz
xK-588a696c685797a2d788ab51f4b85113bd4c5e30.tar.xz
xK-588a696c685797a2d788ab51f4b85113bd4c5e30.zip
degesch: lesser heap fragmentation
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/degesch.c b/degesch.c
index 6aab330..6fce8c8 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1045,22 +1045,21 @@ struct buffer_line
int flags; ///< Flags
time_t when; ///< Time of the event
- struct formatter *formatter; ///< Line data
+ struct formatter formatter; ///< Line data
};
struct buffer_line *
-buffer_line_new (void)
+buffer_line_new (struct formatter *f)
{
struct buffer_line *self = xcalloc (1, sizeof *self);
+ self->formatter = *f;
return self;
}
static void
buffer_line_destroy (struct buffer_line *self)
{
- if (self->formatter)
- formatter_free (self->formatter);
- free (self->formatter);
+ formatter_free (&self->formatter);
free (self);
}
@@ -3052,7 +3051,7 @@ buffer_line_flush (struct buffer_line *line, struct formatter *f, FILE *output,
if (flags & BUFFER_LINE_STATUS) formatter_add (f, " - ");
if (flags & BUFFER_LINE_ERROR) formatter_add (f, "#a=!=#r ", ATTR_ERROR);
- formatter_add_from (f, line->formatter);
+ formatter_add_from (f, &line->formatter);
formatter_add (f, "\n");
formatter_flush (f, output, raw_attributes);
formatter_free (f);
@@ -3142,14 +3141,11 @@ log_formatter (struct app_context *ctx,
if (!buffer)
buffer = ctx->global_buffer;
- struct buffer_line *line = buffer_line_new ();
+ // Move the formatter inside
+ struct buffer_line *line = buffer_line_new (f);
line->flags = flags;
line->when = time (NULL);
- // Move the formatter inside
- line->formatter = xmalloc (sizeof *line->formatter);
- *line->formatter = *f;
-
buffer_pop_excess_lines (ctx, buffer);
LIST_APPEND_WITH_TAIL (buffer->lines, buffer->lines_tail, line);
buffer->lines_count++;